using namespace std;
-Arena arena;
+static int memcmp_different_len(const void *s1, size_t n1, const void *s2, size_t n2)
+{
+ int shared_len = min(n1, n2);
+ int s = memcmp(s1, s2, shared_len);
+ if (s != 0) {
+ return s;
+ }
+
+ if (n1 < n2) {
+ return -1;
+ } else if (n1 > n2) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
enum Result { WHITE = 0, DRAW, BLACK };
struct Element {
long start_position;
bool operator< (const Element& other) const {
- int shared_len = min(bpfen_len, other.bpfen_len);
- int s = memcmp(bpfen, other.bpfen, shared_len);
- if (s < 0) {
- return true;
- } else if (s > 0) {
- return false;
- } else {
- return bpfen_len < other.bpfen_len;
- }
+ int s = memcmp_different_len(bpfen, bpfen_len, other.bpfen, other.bpfen_len);
+ return s < 0;
}
};