|
@@ -1,5 +1,3 @@
|
|
|
-#pragma once
|
|
|
|
|
-
|
|
|
|
|
#if !defined(SMALLMAP_T__HEADER) && !defined(SMALLMAP_T__SOURCE)
|
|
#if !defined(SMALLMAP_T__HEADER) && !defined(SMALLMAP_T__SOURCE)
|
|
|
#include "pocketpy/common/vector.h"
|
|
#include "pocketpy/common/vector.h"
|
|
|
|
|
|
|
@@ -14,6 +12,10 @@
|
|
|
#define less(a, b) ((a.key) < (b))
|
|
#define less(a, b) ((a.key) < (b))
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#ifndef equal
|
|
|
|
|
+ #define equal(a, b) ((a) == (b))
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
/* Temprary macros */
|
|
/* Temprary macros */
|
|
|
#define CONCAT(A, B) CONCAT_(A, B)
|
|
#define CONCAT(A, B) CONCAT_(A, B)
|
|
|
#define CONCAT_(A, B) A##B
|
|
#define CONCAT_(A, B) A##B
|
|
@@ -53,7 +55,7 @@ void SMALLMAP_METHOD(set)(SMALLMAP* self, K key, V value) {
|
|
|
int index;
|
|
int index;
|
|
|
c11__lower_bound(KV, self->data, self->count, key, less, &index);
|
|
c11__lower_bound(KV, self->data, self->count, key, less, &index);
|
|
|
KV* it = c11__at(KV, self, index);
|
|
KV* it = c11__at(KV, self, index);
|
|
|
- if(index != self->count && it->key == key) {
|
|
|
|
|
|
|
+ if(index != self->count && equal(it->key, key)) {
|
|
|
it->value = value;
|
|
it->value = value;
|
|
|
} else {
|
|
} else {
|
|
|
KV kv = {key, value};
|
|
KV kv = {key, value};
|
|
@@ -65,7 +67,7 @@ V* SMALLMAP_METHOD(try_get)(const SMALLMAP* self, K key) {
|
|
|
int index;
|
|
int index;
|
|
|
c11__lower_bound(KV, self->data, self->count, key, less, &index);
|
|
c11__lower_bound(KV, self->data, self->count, key, less, &index);
|
|
|
KV* it = c11__at(KV, self, index);
|
|
KV* it = c11__at(KV, self, index);
|
|
|
- if(index != self->count && it->key == key) {
|
|
|
|
|
|
|
+ if(index != self->count && equal(it->key, key)) {
|
|
|
return &it->value;
|
|
return &it->value;
|
|
|
} else {
|
|
} else {
|
|
|
return NULL;
|
|
return NULL;
|
|
@@ -85,7 +87,7 @@ bool SMALLMAP_METHOD(del)(SMALLMAP* self, K key) {
|
|
|
int index;
|
|
int index;
|
|
|
c11__lower_bound(KV, self->data, self->count, key, less, &index);
|
|
c11__lower_bound(KV, self->data, self->count, key, less, &index);
|
|
|
KV* it = c11__at(KV, self, index);
|
|
KV* it = c11__at(KV, self, index);
|
|
|
- if(index != self->count && it->key == key) {
|
|
|
|
|
|
|
+ if(index != self->count && equal(it->key, key)) {
|
|
|
c11_vector__erase(KV, self, index);
|
|
c11_vector__erase(KV, self, index);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -108,3 +110,4 @@ void SMALLMAP_METHOD(clear)(SMALLMAP* self) {
|
|
|
#undef V
|
|
#undef V
|
|
|
#undef TAG
|
|
#undef TAG
|
|
|
#undef less
|
|
#undef less
|
|
|
|
|
+#undef equal
|