|
@@ -10,24 +10,24 @@
|
|
|
|
|
|
LSUP_TripleKey NULL_TRP = {NULL_KEY, NULL_KEY, NULL_KEY};
|
|
LSUP_TripleKey NULL_TRP = {NULL_KEY, NULL_KEY, NULL_KEY};
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * CALLBACKS
|
|
|
|
|
|
+ * Callback type for key comparison.
|
|
*/
|
|
*/
|
|
-
|
|
|
|
typedef bool (*LSUP_key_cmp_fn_t)(
|
|
typedef bool (*LSUP_key_cmp_fn_t)(
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2);
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2);
|
|
|
|
|
|
-// Keyset lookup for S LSUP_Key.
|
|
|
|
|
|
+// Keyset lookup for S key.
|
|
static inline bool lookup_sk_cmp_fn(
|
|
static inline bool lookup_sk_cmp_fn(
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
|
|
{ return spok[0][0] == k1; }
|
|
{ return spok[0][0] == k1; }
|
|
|
|
|
|
-// Keyset lookup for P LSUP_Key.
|
|
|
|
|
|
+// Keyset lookup for P key.
|
|
static inline bool lookup_pk_cmp_fn(
|
|
static inline bool lookup_pk_cmp_fn(
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
|
|
{ return spok[0][1] == k1; }
|
|
{ return spok[0][1] == k1; }
|
|
|
|
|
|
-// Keyset lookup for O LSUP_Key.
|
|
|
|
|
|
+// Keyset lookup for O key.
|
|
static inline bool lookup_ok_cmp_fn(
|
|
static inline bool lookup_ok_cmp_fn(
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
|
|
const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
|
|
{ return spok[0][2] == k1; }
|
|
{ return spok[0][2] == k1; }
|
|
@@ -58,7 +58,7 @@ static inline bool lookup_none_cmp_fn(
|
|
bool LSUP_keyset_seek(LSUP_Keyset* ks, size_t idx);
|
|
bool LSUP_keyset_seek(LSUP_Keyset* ks, size_t idx);
|
|
size_t LSUP_keyset_size(LSUP_Keyset* ks);
|
|
size_t LSUP_keyset_size(LSUP_Keyset* ks);
|
|
size_t LSUP_keyset_tell(LSUP_Keyset* ks);
|
|
size_t LSUP_keyset_tell(LSUP_Keyset* ks);
|
|
-const LSUP_TripleKey *LSUP_keyset_peek(LSUP_Keyset *ks);
|
|
|
|
|
|
+LSUP_TripleKey *LSUP_keyset_peek(LSUP_Keyset *ks);
|
|
bool LSUP_keyset_contains(
|
|
bool LSUP_keyset_contains(
|
|
const LSUP_Keyset *ks, const LSUP_TripleKey *val);
|
|
const LSUP_Keyset *ks, const LSUP_TripleKey *val);
|
|
bool LSUP_keyset_next(LSUP_Keyset *ks);
|
|
bool LSUP_keyset_next(LSUP_Keyset *ks);
|
|
@@ -75,22 +75,21 @@ static inline bool is_null_trp(const LSUP_TripleKey *trp)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-int LSUP_keyset_init(LSUP_Keyset *ks, size_t capacity, float expand_ratio)
|
|
|
|
|
|
+int LSUP_keyset_init(LSUP_Keyset *ks, size_t capacity)
|
|
{
|
|
{
|
|
CRITICAL (ks->data = malloc(capacity * TRP_KLEN));
|
|
CRITICAL (ks->data = malloc(capacity * TRP_KLEN));
|
|
ks->capacity = capacity;
|
|
ks->capacity = capacity;
|
|
ks->cur = 0;
|
|
ks->cur = 0;
|
|
ks->free_i = 0;
|
|
ks->free_i = 0;
|
|
- ks->expand_ratio = expand_ratio;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-LSUP_Keyset *LSUP_keyset_new(size_t capacity, float expand_ratio) {
|
|
|
|
|
|
+LSUP_Keyset *LSUP_keyset_new(size_t capacity) {
|
|
LSUP_Keyset *ks = malloc(sizeof(LSUP_Keyset));
|
|
LSUP_Keyset *ks = malloc(sizeof(LSUP_Keyset));
|
|
|
|
|
|
- LSUP_keyset_init(ks, capacity, expand_ratio);
|
|
|
|
|
|
+ LSUP_keyset_init(ks, capacity);
|
|
|
|
|
|
return(ks);
|
|
return(ks);
|
|
}
|
|
}
|
|
@@ -127,19 +126,13 @@ int LSUP_keyset_resize(LSUP_Keyset *ks, size_t new_size) {
|
|
|
|
|
|
|
|
|
|
int LSUP_keyset_add(
|
|
int LSUP_keyset_add(
|
|
- LSUP_Keyset *ks, const LSUP_TripleKey *val, LSUP_KSFlag flags)
|
|
|
|
|
|
+ LSUP_Keyset *ks, const LSUP_TripleKey *val, const LSUP_KSFlag flags)
|
|
{
|
|
{
|
|
if((flags & LSUP_KS_CHECK_DUP) && LSUP_keyset_contains(ks, val))
|
|
if((flags & LSUP_KS_CHECK_DUP) && LSUP_keyset_contains(ks, val))
|
|
return 1;
|
|
return 1;
|
|
|
|
|
|
- if((flags & LSUP_KS_CHECK_CAP) && ks->free_i >= ks->capacity) {
|
|
|
|
- if(ks->expand_ratio > 0) {
|
|
|
|
- LSUP_keyset_resize(
|
|
|
|
- ks, 1 + (size_t)(ks->capacity * (1 + ks->expand_ratio)));
|
|
|
|
- } else {
|
|
|
|
- return -2; // TODO: ENOMEM
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if((flags & LSUP_KS_CHECK_CAP) && ks->free_i >= ks->capacity)
|
|
|
|
+ LSUP_keyset_resize(ks, ks->capacity * 2);
|
|
|
|
|
|
memcpy(ks->data + ks->free_i, val, TRP_KLEN);
|
|
memcpy(ks->data + ks->free_i, val, TRP_KLEN);
|
|
|
|
|
|
@@ -168,7 +161,7 @@ int LSUP_keyset_remove(LSUP_Keyset *ks, const LSUP_TripleKey *val) {
|
|
|
|
|
|
int LSUP_keyset_copy(const LSUP_Keyset *src, LSUP_Keyset *dest) {
|
|
int LSUP_keyset_copy(const LSUP_Keyset *src, LSUP_Keyset *dest) {
|
|
|
|
|
|
- LSUP_keyset_init(dest, src->capacity, src->expand_ratio);
|
|
|
|
|
|
+ LSUP_keyset_init(dest, src->capacity);
|
|
|
|
|
|
memcpy(dest->data, src->data, src->capacity * TRP_KLEN);
|
|
memcpy(dest->data, src->data, src->capacity * TRP_KLEN);
|
|
|
|
|
|
@@ -181,7 +174,7 @@ int LSUP_keyset_copy(const LSUP_Keyset *src, LSUP_Keyset *dest) {
|
|
|
|
|
|
int LSUP_keyset_sparse_copy(LSUP_Keyset *src, LSUP_Keyset *dest) {
|
|
int LSUP_keyset_sparse_copy(LSUP_Keyset *src, LSUP_Keyset *dest) {
|
|
|
|
|
|
- LSUP_keyset_init(dest, src->capacity, src->expand_ratio);
|
|
|
|
|
|
+ LSUP_keyset_init(dest, src->capacity);
|
|
|
|
|
|
if (LSUP_keyset_seek(src, 0)) {
|
|
if (LSUP_keyset_seek(src, 0)) {
|
|
do {
|
|
do {
|
|
@@ -268,84 +261,6 @@ int LSUP_keyset_lookup(
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-int LSUP_keyset_join(LSUP_Keyset *ks1, LSUP_Keyset *ks2, LSUP_Keyset *res)
|
|
|
|
-{
|
|
|
|
- LSUP_keyset_sparse_copy(ks1, res);
|
|
|
|
-
|
|
|
|
- if (LSUP_keyset_seek(ks2, 0)) {
|
|
|
|
- do {
|
|
|
|
- const LSUP_TripleKey *spok = LSUP_keyset_peek(ks2);
|
|
|
|
- if (!is_null_trp(spok)) {
|
|
|
|
- LSUP_keyset_add(
|
|
|
|
- res, spok, LSUP_KS_CHECK_DUP | LSUP_KS_CHECK_CAP);
|
|
|
|
- }
|
|
|
|
- } while (LSUP_keyset_next(ks2));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-int LSUP_keyset_subtract(LSUP_Keyset *ks1, LSUP_Keyset *ks2, LSUP_Keyset *res)
|
|
|
|
-{
|
|
|
|
- LSUP_keyset_init(res, ks1->capacity, ks1->expand_ratio);
|
|
|
|
-
|
|
|
|
- if (LSUP_keyset_seek(ks1, 0)) {
|
|
|
|
- do {
|
|
|
|
- const LSUP_TripleKey *spok = LSUP_keyset_peek(ks1);
|
|
|
|
- if (!is_null_trp(spok) && !LSUP_keyset_contains(ks2, spok)) {
|
|
|
|
- LSUP_keyset_add(res, spok, 0);
|
|
|
|
- }
|
|
|
|
- } while (LSUP_keyset_next(ks1));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-int LSUP_keyset_intersect(LSUP_Keyset *ks1, LSUP_Keyset *ks2, LSUP_Keyset *res)
|
|
|
|
-{
|
|
|
|
- LSUP_keyset_init(res, ks1->capacity, ks1->expand_ratio);
|
|
|
|
-
|
|
|
|
- if (LSUP_keyset_seek(ks1, 0)) {
|
|
|
|
- do {
|
|
|
|
- const LSUP_TripleKey *spok = LSUP_keyset_peek(ks1);
|
|
|
|
- if (!is_null_trp(spok) && LSUP_keyset_contains(ks2, spok)) {
|
|
|
|
- LSUP_keyset_add(res, spok, 0);
|
|
|
|
- }
|
|
|
|
- } while (LSUP_keyset_next(ks1));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-int LSUP_keyset_xor(LSUP_Keyset *ks1, LSUP_Keyset *ks2, LSUP_Keyset *res)
|
|
|
|
-{
|
|
|
|
- LSUP_keyset_init(res, ks1->capacity + ks2->capacity, ks1->expand_ratio);
|
|
|
|
-
|
|
|
|
- if (LSUP_keyset_seek(ks1, 0)) {
|
|
|
|
- do {
|
|
|
|
- const LSUP_TripleKey *spok = LSUP_keyset_peek(ks1);
|
|
|
|
- if (!is_null_trp(spok) && !LSUP_keyset_contains(ks2, spok)) {
|
|
|
|
- LSUP_keyset_add(res, spok, 0);
|
|
|
|
- }
|
|
|
|
- } while (LSUP_keyset_next(ks1));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (LSUP_keyset_seek(ks2, 0)) {
|
|
|
|
- do {
|
|
|
|
- const LSUP_TripleKey *spok = LSUP_keyset_peek(ks2);
|
|
|
|
- if (!is_null_trp(spok) && !LSUP_keyset_contains(ks1, spok)) {
|
|
|
|
- LSUP_keyset_add(res, spok, 0);
|
|
|
|
- }
|
|
|
|
- } while (LSUP_keyset_next(ks2));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
void LSUP_keyset_done(LSUP_Keyset *ks)
|
|
void LSUP_keyset_done(LSUP_Keyset *ks)
|
|
{
|
|
{
|
|
if(LIKELY(ks->data != NULL))
|
|
if(LIKELY(ks->data != NULL))
|