瀏覽代碼

Remove merged modules.

Stefano Cossu 4 年之前
父節點
當前提交
0531b9ba8d
共有 8 個文件被更改,包括 1 次插入871 次删除
  1. 0 39
      include/index.h
  2. 0 109
      include/keyset.h
  3. 0 1
      include/lsup_rdf.h
  4. 0 95
      src/index.c
  5. 0 279
      src/keyset.c
  6. 1 5
      test.c
  7. 0 126
      test/test_index.c
  8. 0 217
      test/test_keyset.c

+ 0 - 39
include/index.h

@@ -1,39 +0,0 @@
-/** Limited-scope, fast implementation of a bi-directional hash table.
- *
- * This data structure holds an array of key-value pairs. It is append-only.
- *
- * A key is the result of a hash function applied to the value, and keys are
- * unique within an index. Hence, both keys and values are uniqure and lookups
- * can be done both ways.
- *
- * A value is a pointer to a `LSUP_SerTerm` structure. Comparison for
- * uniqueness is done by comparing the hashes/keys.
- *
- * To find a key by its value, it is sufficient to apply the hash function to
- * the value without having to look up the table.
- */
-
-#include "buffer.h"
-#include "term.h"
-
-typedef struct Index LSUP_Index;
-
-LSUP_Index *LSUP_index_new(size_t capacity);
-
-/**
- * Add a key/value pair. The key must be calculated in advance.
- *
- * This function takes ownership of the serialized term.
- */
-int LSUP_index_add_pair(LSUP_Index *idx, LSUP_Key key, LSUP_SerTerm *sterm);
-
-/**
- * Add a term and automatically calculate the key.
- *
- * This function takes ownership of the serialized term.
- */
-int LSUP_index_add(LSUP_Index *idx, LSUP_SerTerm *sterm);
-
-LSUP_SerTerm *LSUP_index_lookup(LSUP_Index *idx, LSUP_Key key);
-
-void LSUP_index_free(LSUP_Index *idx);

+ 0 - 109
include/keyset.h

@@ -1,109 +0,0 @@
-#ifndef LSUP_KEYSET_H
-#define LSUP_KEYSET_H
-
-#include "core.h"
-
-typedef enum LSUP_KSFlag {
-    LSUP_KS_NONE        = 0,
-    LSUP_KS_CHECK_CAP   = 1 << 0,
-    LSUP_KS_CHECK_DUP   = 1 << 1
-} LSUP_KSFlag;
-
-typedef struct keyset {
-    LSUP_TripleKey  *data;
-    size_t          capacity;
-    size_t          cur;
-    size_t          free_i;
-} LSUP_Keyset;
-
-
-int LSUP_keyset_init(LSUP_Keyset *ks, size_t capacity);
-
-LSUP_Keyset *LSUP_keyset_new(size_t capacity);
-
-
-/**
- * Move cursor to a non-empty position.
- */
-inline bool LSUP_keyset_seek(LSUP_Keyset* ks, size_t idx)
-{
-    if (idx >= ks->free_i) return false;
-
-    ks->cur = idx;
-
-    return true;
-}
-
-
-inline size_t LSUP_keyset_size(LSUP_Keyset* ks)
-{
-    return(ks->free_i);
-}
-
-
-inline size_t LSUP_keyset_tell(LSUP_Keyset* ks)
-{
-    return(ks->cur);
-}
-
-
-inline LSUP_TripleKey *LSUP_keyset_peek(LSUP_Keyset *ks) {
-    return ks->data + ks->cur;
-}
-
-
-inline bool LSUP_keyset_contains(
-        const LSUP_Keyset *ks, const LSUP_TripleKey *val) {
-
-    for (size_t i = 0; i < ks->free_i; i++) {
-        // scan from the least to the most probable to match.
-        if (
-                (*val)[2] == ks->data[i][2] &&
-                (*val)[0] == ks->data[i][0] &&
-                (*val)[1] == ks->data[i][1]) {
-            return true;
-        }
-    }
-
-    return false;
-}
-
-
-inline bool LSUP_keyset_next(LSUP_Keyset *ks)
-{
-    if (ks->free_i > 0 && ks->cur < ks->free_i - 1) {
-        ks->cur ++;
-        return true;
-    }
-    return false;
-}
-
-/**
- * Resize the keyset capacity.
- *
- * Size cannot be smaller than `free_i`. Therefore, specifying a size of 0 will
- * always compact the keyset to the current occupied space.
- */
-int LSUP_keyset_resize(LSUP_Keyset *ks, size_t new_size);
-
-/**
- * Add a single key.
- */
-int LSUP_keyset_add(
-        LSUP_Keyset *ks, const LSUP_TripleKey *val, const LSUP_KSFlag flags);
-
-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_sparse_copy(LSUP_Keyset *src, LSUP_Keyset *dest);
-
-int LSUP_keyset_lookup(
-        LSUP_Keyset *ks, LSUP_Keyset *res,
-        const LSUP_Key sk, const LSUP_Key pk, const LSUP_Key ok);
-
-void LSUP_keyset_done(LSUP_Keyset *ks);
-
-void LSUP_keyset_free(LSUP_Keyset *ks);
-
-#endif

+ 0 - 1
include/lsup_rdf.h

@@ -2,6 +2,5 @@
 #define _LSUP_RDF_H
 
 #include "graph.h"
-#include "keyset.h"
 
 #endif

+ 0 - 95
src/index.c

@@ -1,95 +0,0 @@
-#include "index.h"
-
-struct IndexEntry {
-    LSUP_Key key;
-    LSUP_SerTerm *val;
-};
-
-struct Index {
-    size_t free_i;
-    size_t capacity;
-    struct IndexEntry *entries;
-};
-
-
-LSUP_Index *LSUP_index_new(size_t capacity)
-{
-    LSUP_Index *idx = malloc(sizeof(struct Index));
-
-    if (capacity == 0) return NULL;
-
-    CRITICAL (idx->entries = malloc(sizeof(struct IndexEntry) * capacity));
-
-    idx->free_i = 0;
-    idx->capacity = capacity;
-
-    return idx;
-}
-
-
-void LSUP_index_resize(LSUP_Index *idx, size_t capacity)
-{
-    CRITICAL (idx->entries = (struct IndexEntry*)realloc(
-            idx->entries,
-            sizeof(struct IndexEntry) * capacity));
-
-    idx->capacity = capacity;
-}
-
-
-int LSUP_index_add(LSUP_Index *idx, LSUP_SerTerm *sterm)
-{
-    LSUP_Key key = LSUP_sterm_to_key(sterm);
-
-    return LSUP_index_add_pair(idx, key, sterm);
-}
-
-
-int LSUP_index_add_pair(LSUP_Index *idx, LSUP_Key key, LSUP_SerTerm *sterm)
-{
-    // Fail quietly if key exists already.
-    if (LSUP_index_lookup(idx, key) == NULL) {
-        if (idx->free_i >= idx->capacity) {
-            LSUP_index_resize(idx, idx->capacity * 1.5);
-            TRACE("Capacity now at %lu\n", idx->capacity);
-        }
-
-        struct IndexEntry *entry = idx->entries + idx->free_i;
-
-        entry->key = key;
-        entry->val = LSUP_buffer_new(sterm->size);
-        memcpy(entry->val->addr, sterm->addr, sterm->size);
-
-        idx->free_i ++;
-        TRACE("Size now at %lu\n", idx->free_i);
-
-    }
-
-    return 0;
-}
-
-
-LSUP_SerTerm *LSUP_index_lookup(LSUP_Index *idx, LSUP_Key key)
-{
-    LSUP_SerTerm *match = NULL;
-
-    for (size_t i = 0; i < idx->free_i; i++) {
-        if (idx->entries[i].key == key) {
-            match = idx->entries[i].val;
-            break;
-        }
-    }
-
-    return match;
-}
-
-void LSUP_index_free(LSUP_Index *idx)
-{
-    for (size_t i = 0; i < idx->free_i; i++) {
-        LSUP_buffer_done(idx->entries[i].val);
-        free(idx->entries[i].val);
-    }
-
-    free(idx->entries);
-    free(idx);
-}

+ 0 - 279
src/keyset.c

@@ -1,279 +0,0 @@
-#include <math.h>
-
-#include "keyset.h"
-
-#define KLEN sizeof(LSUP_Key)
-#define DBL_KLEN sizeof(LSUP_DoubleKey)
-#define TRP_KLEN sizeof(LSUP_TripleKey)
-#define QUAD_KLEN sizeof(LSUP_QuadKey)
-
-
-LSUP_TripleKey NULL_TRP = {NULL_KEY, NULL_KEY, NULL_KEY};
-
-
-/**
- * Callback type for key comparison.
- */
-typedef bool (*LSUP_key_cmp_fn_t)(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2);
-
-//  Keyset lookup for S key.
-static inline bool lookup_sk_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return spok[0][0] == k1; }
-
-//  Keyset lookup for P key.
-static inline bool lookup_pk_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return spok[0][1] == k1; }
-
-//  Keyset lookup for O key.
-static inline bool lookup_ok_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return spok[0][2] == k1; }
-
-//  Keyset lookup for S and P keys.
-static inline bool lookup_skpk_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return spok[0][0] == k1 && spok[0][1] == k2; }
-
-//  Keyset lookup for S and O keys.
-static inline bool lookup_skok_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return spok[0][0] == k1 && spok[0][2] == k2; }
-
-//  Keyset lookup for P and O keys.
-static inline bool lookup_pkok_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return spok[0][1] == k1 && spok[0][2] == k2; }
-
-// Dummy callback for queries with all parameters unbound. Returns true.
-static inline bool lookup_none_cmp_fn(
-        const LSUP_TripleKey* spok, const LSUP_Key k1, const LSUP_Key k2)
-{ return true; }
-
-
-// Inline extern prototypes.
-
-bool LSUP_keyset_seek(LSUP_Keyset* ks, size_t idx);
-size_t LSUP_keyset_size(LSUP_Keyset* ks);
-size_t LSUP_keyset_tell(LSUP_Keyset* ks);
-LSUP_TripleKey *LSUP_keyset_peek(LSUP_Keyset *ks);
-bool LSUP_keyset_contains(
-        const LSUP_Keyset *ks, const LSUP_TripleKey *val);
-bool LSUP_keyset_next(LSUP_Keyset *ks);
-
-
-// Inline utils.
-
-static inline bool is_null_trp(const LSUP_TripleKey *trp)
-{
-    return (
-            (*trp)[0] == NULL_TRP[0]
-            && (*trp)[1] == NULL_TRP[1]
-            && (*trp)[2] == NULL_TRP[2]);
-}
-
-
-int LSUP_keyset_init(LSUP_Keyset *ks, size_t capacity)
-{
-    CRITICAL (ks->data = malloc(capacity * TRP_KLEN));
-    ks->capacity = capacity;
-    ks->cur = 0;
-    ks->free_i = 0;
-
-    return 0;
-}
-
-
-LSUP_Keyset *LSUP_keyset_new(size_t capacity) {
-    LSUP_Keyset *ks = malloc(sizeof(LSUP_Keyset));
-
-    LSUP_keyset_init(ks, capacity);
-
-    return(ks);
-}
-
-
-/**
- * Populate the provided `val` variable with the next available record.
- *
- * If the cursor is already at the last record, `val` is set to `NULL`.
- *
- * NOTE: This function copies data. For no-copy peek, use `LSUP_keyset_peek()`.
- */
-bool LSUP_keyset_get_next(LSUP_Keyset *ks, LSUP_TripleKey *val) {
-
-    if (LSUP_keyset_next(ks)) {
-        memcpy(val, ks->data + ks->cur, TRP_KLEN);
-
-        return(1);
-    } else {
-        val = NULL;
-        return(0);
-    }
-}
-
-
-int LSUP_keyset_resize(LSUP_Keyset *ks, size_t new_size) {
-    new_size = max(new_size, ks->free_i);
-
-    CRITICAL (ks->data = realloc(
-            ks->data, max(new_size, ks->free_i) * TRP_KLEN))
-
-    return(0);
-}
-
-
-int LSUP_keyset_add(
-        LSUP_Keyset *ks, const LSUP_TripleKey *val, const LSUP_KSFlag flags)
-{
-    if((flags & LSUP_KS_CHECK_DUP) && LSUP_keyset_contains(ks, val))
-        return 1;
-
-    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);
-
-    ks->cur = ks->free_i;
-    ks->free_i ++;
-
-    return(0);
-}
-
-
-int LSUP_keyset_remove(LSUP_Keyset *ks, const LSUP_TripleKey *val) {
-
-    LSUP_keyset_seek(ks, 0);
-
-    while (LSUP_keyset_next(ks)) {
-        if (memcmp(val, ks->data + ks->cur, TRP_KLEN) == 0) {
-            memcpy(ks->data + ks->cur, &NULL_TRP, TRP_KLEN);
-
-            break;
-        }
-    }
-
-    return(0);
-}
-
-
-int LSUP_keyset_copy(const LSUP_Keyset *src, LSUP_Keyset *dest) {
-
-    LSUP_keyset_init(dest, src->capacity);
-
-    memcpy(dest->data, src->data, src->capacity * TRP_KLEN);
-
-    LSUP_keyset_seek(dest, 0);
-    dest->free_i = src->free_i;
-
-    return(0);
-}
-
-
-int LSUP_keyset_sparse_copy(LSUP_Keyset *src, LSUP_Keyset *dest) {
-
-    LSUP_keyset_init(dest, src->capacity);
-
-    if (LSUP_keyset_seek(src, 0)) {
-        do {
-            if (LIKELY(memcmp(
-                            LSUP_keyset_peek(src),
-                            &NULL_TRP, TRP_KLEN) != 0)) {
-                LSUP_keyset_add(dest, LSUP_keyset_peek(src), 0);
-            }
-        } while (LSUP_keyset_next(src));
-
-        LSUP_keyset_seek(dest, 0);
-    }
-
-    return(0);
-}
-
-
-int LSUP_keyset_lookup(
-        LSUP_Keyset *ks, LSUP_Keyset *res,
-        const LSUP_Key sk, const LSUP_Key pk, const LSUP_Key ok) {
-
-    LSUP_Key k1, k2;
-    LSUP_key_cmp_fn_t cmp_fn;
-
-    if (sk && pk && ok) {
-        LSUP_keyset_init(res, 1, 1);
-        LSUP_TripleKey spok = {sk, pk, ok};
-        if(LSUP_keyset_contains(ks, &spok)) {
-            LSUP_keyset_add(res, &spok, 0);
-            return 0;
-        } else {
-            return 1;
-        }
-
-    } else if (sk) {
-        k1 = sk;
-
-        if (pk) { // s p ?
-            k2 = pk;
-            cmp_fn = lookup_skpk_cmp_fn;
-
-        } else if (ok) { // s ? o
-            k2 = ok;
-            cmp_fn = lookup_skok_cmp_fn;
-
-        } else { // s ? ?
-            cmp_fn = lookup_sk_cmp_fn;
-
-        }
-
-    } else if (pk) {
-        k1 = pk;
-
-        if (ok) { // ? p o
-            k2 = ok;
-            cmp_fn = lookup_pkok_cmp_fn;
-
-        } else { // ? p ?
-            cmp_fn = lookup_pk_cmp_fn;
-        }
-
-    } else if (ok) { // ? ? o
-        k1 = ok;
-        cmp_fn = lookup_ok_cmp_fn;
-
-    } else {
-        printf("WARNING: no bound terms, making a compact copy.\n");
-        return LSUP_keyset_sparse_copy(ks, res);
-    }
-
-    LSUP_keyset_init(res, ks->capacity, ks->expand_ratio);
-
-    LSUP_keyset_seek(ks, 0);
-    do {
-        if (cmp_fn(LSUP_keyset_peek(ks), k1, k2)) {
-            LSUP_keyset_add(res, LSUP_keyset_peek(ks), 0);
-        }
-    } while (LSUP_keyset_next(ks));
-
-    // Compact result keyset.
-    LSUP_keyset_resize(res, 0);
-
-    return 0;
-}
-
-
-void LSUP_keyset_done(LSUP_Keyset *ks)
-{
-    if(LIKELY(ks->data != NULL))
-        free(ks->data);
-}
-
-
-void LSUP_keyset_free(LSUP_Keyset *ks)
-{
-    if(LIKELY(ks != NULL)) {
-        LSUP_keyset_done(ks);
-        free(ks);
-    }
-}
-
-

+ 1 - 5
test.c

@@ -1,13 +1,9 @@
 #include "test_term.c"
-#include "test_index.c"
 #include "test_graph.c"
-#include "test_keyset.c"
 
 int main(int argc, char **argv) {
 
-    int result = (
-            term_tests() | index_tests()
-            | keyset_tests() | graph_tests());
+    int result = (term_tests() | graph_tests());
 
     printf("Test result: %lu\n", (size_t)result);
 

+ 0 - 126
test/test_index.c

@@ -1,126 +0,0 @@
-#include "test.h"
-
-static int test_index_add()
-{
-    LSUP_Term *uri = LSUP_term_new(
-            LSUP_TERM_URI, "http://hello.org", NULL, NULL);
-    LSUP_Term *lit = LSUP_term_new(
-            LSUP_TERM_LITERAL, "hello", NULL, NULL);
-    LSUP_Term *tlit = LSUP_term_new(
-            LSUP_TERM_LITERAL, "hello", "xsd:string", NULL);
-    LSUP_Term *tllit1 = LSUP_term_new(
-            LSUP_TERM_LITERAL, "hello", "xsd:string", "en-US");
-    LSUP_Term *tllit2 = LSUP_term_new(
-            LSUP_TERM_LITERAL, "hello", "xsd:string", "en-GB");
-
-    // Make capacity lower intentionally, to test expansion.
-    LSUP_Index *idx = LSUP_index_new(3);
-    LSUP_Key key;
-
-    LSUP_SerTerm *s_uri = malloc(sizeof(LSUP_SerTerm));
-    LSUP_term_serialize(uri, s_uri);
-    LSUP_index_add(idx, s_uri);
-
-    key = LSUP_term_to_key(uri);
-    ASSERT(
-            LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_uri),
-            "URI not found!");
-
-    LSUP_SerTerm *s_lit = malloc(sizeof(LSUP_SerTerm));
-    LSUP_term_serialize(lit, s_lit);
-    LSUP_index_add(idx, s_lit);
-
-    key = LSUP_term_to_key(lit);
-    ASSERT(
-            LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_lit),
-            "Literal not found!");
-
-    LSUP_SerTerm *s_tlit = malloc(sizeof(LSUP_SerTerm));
-    LSUP_term_serialize(tlit, s_tlit);
-    LSUP_index_add(idx, s_tlit);
-
-    key = LSUP_term_to_key(tlit);
-    ASSERT(
-            LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_tlit),
-            "Typed literal not found!");
-
-    LSUP_SerTerm *s_tllit1 = malloc(sizeof(LSUP_SerTerm));
-    LSUP_term_serialize(tllit1, s_tllit1);
-    LSUP_index_add(idx, s_tllit1);
-
-    key = LSUP_term_to_key(tllit1);
-    ASSERT(
-            LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_tllit1),
-            "US lang literal not found!");
-
-    LSUP_SerTerm *s_tllit2 = malloc(sizeof(LSUP_SerTerm));
-    LSUP_term_serialize(tllit2, s_tllit2);
-    LSUP_index_add(idx, s_tllit2);
-
-    key = LSUP_term_to_key(tllit2);
-    ASSERT(
-            LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_tllit2),
-            "GB lang literal not found!");
-
-    LSUP_term_free(uri);
-    LSUP_term_free(lit);
-    LSUP_term_free(tlit);
-    LSUP_term_free(tllit1);
-    LSUP_term_free(tllit2);
-
-    LSUP_index_free(idx);
-
-    LSUP_buffer_done(s_uri);
-    free(s_uri);
-    LSUP_buffer_done(s_lit);
-    free(s_lit);
-    LSUP_buffer_done(s_tlit);
-    free(s_tlit);
-    LSUP_buffer_done(s_tllit1);
-    free(s_tllit1);
-    LSUP_buffer_done(s_tllit2);
-    free(s_tllit2);
-
-    return 0;
-}
-
-
-int test_index_add_pair()
-{
-    LSUP_Term *uri = LSUP_term_new(
-            LSUP_TERM_URI, "http://hello.org", NULL, NULL);
-
-    LSUP_Index *idx = LSUP_index_new(1);
-
-    LSUP_SerTerm *s_uri = malloc(sizeof(LSUP_SerTerm));
-    LSUP_term_serialize(uri, s_uri);
-    LSUP_index_add(idx, s_uri);
-
-    LSUP_Key key;
-
-    key = LSUP_term_to_key(uri);
-
-    LSUP_index_add_pair(idx, key, s_uri);
-
-    ASSERT(
-            LSUP_buffer_eq(LSUP_index_lookup(idx, key), s_uri),
-            "URI not found!");
-
-
-    LSUP_index_free(idx);
-    LSUP_term_free(uri);
-    LSUP_buffer_done(s_uri);
-    free(s_uri);
-
-    return 0;
-}
-
-
-int index_tests() {
-    RUN(test_index_add);
-    RUN(test_index_add_pair);
-
-    return 0;
-}
-
-

+ 0 - 217
test/test_keyset.c

@@ -1,217 +0,0 @@
-#include "test.h"
-
-int test_keyset_stack()
-{
-    LSUP_Keyset ks_s;
-    LSUP_Keyset *ks = &ks_s;
-
-    LSUP_keyset_init(ks, 10, .5);
-
-    EXPECT_INT_EQ(ks->capacity, 10);
-
-    LSUP_keyset_done(ks);
-
-    return 0;
-}
-
-
-int test_keyset_heap()
-{
-    LSUP_Keyset *ks = LSUP_keyset_new(10, .5);
-
-    EXPECT_INT_EQ(ks->capacity, 10);
-
-    LSUP_keyset_free(ks);
-
-    return 0;
-}
-
-
-int test_keyset_add_remove()
-{
-    LSUP_Keyset *ks = LSUP_keyset_new(10, .5);
-
-    LSUP_TripleKey k1 = {1,1,1};
-    LSUP_TripleKey k2 = {1,1,2};
-    LSUP_TripleKey k3 = {1,1,3};
-    LSUP_TripleKey k4 = {1,2,1};
-    LSUP_TripleKey k5 = {1,2,1}; // Duplicate
-
-    LSUP_keyset_add(ks, &k1, LSUP_KS_CHECK_DUP);
-    LSUP_keyset_add(ks, &k2, LSUP_KS_CHECK_DUP);
-    LSUP_keyset_add(ks, &k3, LSUP_KS_CHECK_DUP);
-    LSUP_keyset_add(ks, &k4, LSUP_KS_CHECK_DUP);
-    LSUP_keyset_add(ks, &k5, LSUP_KS_CHECK_DUP);
-
-    EXPECT_INT_EQ(LSUP_keyset_size(ks), 4);
-    EXPECT_INT_EQ(LSUP_keyset_tell(ks), 3);
-
-    EXPECT_INT_EQ(LSUP_keyset_seek(ks, 1), true);
-    ASSERT(
-            memcmp(LSUP_keyset_peek(ks), &k2, sizeof(LSUP_TripleKey)) == 0,
-            "Key not corresponding to index!");
-
-    LSUP_TripleKey k6 = {1,1,2};
-    LSUP_keyset_remove(ks, &k6);
-
-    ASSERT(!LSUP_keyset_contains(ks, &k6), "Triple not removed!");
-    ASSERT(!LSUP_keyset_contains(ks, &k2), "Triple not removed!");
-
-    EXPECT_INT_EQ(ks->free_i, 4);
-
-    LSUP_Keyset *ks2 = malloc(sizeof(LSUP_Keyset));
-    LSUP_keyset_sparse_copy(ks, ks2);
-
-    EXPECT_INT_EQ(ks2->free_i, 3);
-
-    LSUP_keyset_free(ks);
-    LSUP_keyset_free(ks2);
-
-    return 0;
-}
-
-
-int test_keyset_lookup()
-{
-    LSUP_Keyset *ks = LSUP_keyset_new(10, .5);
-    LSUP_Keyset res_s;
-    LSUP_Keyset *res = &res_s;
-
-    LSUP_TripleKey k1 = {1,1,1};
-    LSUP_TripleKey k2 = {1,1,2};
-    LSUP_TripleKey k3 = {1,2,1};
-    LSUP_TripleKey k4 = {2,1,3};
-
-    LSUP_keyset_add(ks, &k1, 0);
-    LSUP_keyset_add(ks, &k2, 0);
-    LSUP_keyset_add(ks, &k3, 0);
-    LSUP_keyset_add(ks, &k4, 0);
-
-    LSUP_keyset_lookup(ks, res, 1, 1, 1);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 1);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_lookup(ks, res, 1, 1, 0);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 2);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_lookup(ks, res, 1, 2, 0);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 1);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_lookup(ks, res, 1, 0, 0);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 3);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_lookup(ks, res, 0, 1, 0);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 3);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_lookup(ks, res, 0, 0, 0);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 4);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_free(ks);
-
-    return 0;
-}
-
-
-int test_keyset_bool_ops()
-{
-    LSUP_Keyset res_s;
-    LSUP_Keyset *res = &res_s;
-
-    LSUP_TripleKey k1 = {1,1,1};
-    LSUP_TripleKey k2 = {1,1,2};
-    LSUP_TripleKey k3 = {1,2,1};
-    LSUP_TripleKey k4 = {2,1,3};
-    LSUP_TripleKey k5 = {3,1,1};
-
-    LSUP_TripleKey k6 = {1,1,1};
-    LSUP_TripleKey k7 = {1,1,2};
-    LSUP_TripleKey k8 = {3,2,1};
-    LSUP_TripleKey k9 = {4,1,3};
-    LSUP_TripleKey k10 = {5,1,3};
-
-    LSUP_Keyset *ks1 = LSUP_keyset_new(5, .5);
-    LSUP_Keyset *ks2 = LSUP_keyset_new(5, .5);
-
-    // Both sets empty.
-    LSUP_keyset_join(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 0);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_subtract(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 0);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_intersect(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 0);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_xor(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 0);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_add(ks1, &k1, 0);
-    LSUP_keyset_add(ks1, &k2, 0);
-    LSUP_keyset_add(ks1, &k3, 0);
-    LSUP_keyset_add(ks1, &k4, 0);
-    LSUP_keyset_add(ks1, &k5, 0);
-
-    // Set 2 empty.
-    LSUP_keyset_join(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 5);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_subtract(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 5);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_intersect(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 0);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_xor(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 5);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_add(ks2, &k6, 0);
-    LSUP_keyset_add(ks2, &k7, 0);
-    LSUP_keyset_add(ks2, &k8, 0);
-    LSUP_keyset_add(ks2, &k9, 0);
-    LSUP_keyset_add(ks2, &k10, 0);
-
-    // Both sets populated.
-    LSUP_keyset_join(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 8);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_subtract(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 3);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_intersect(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 2);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_xor(ks1, ks2, res);
-    EXPECT_INT_EQ(LSUP_keyset_size(res), 6);
-    LSUP_keyset_done(res);
-
-    LSUP_keyset_free(ks1);
-    LSUP_keyset_free(ks2);
-
-    return 0;
-}
-
-int keyset_tests()
-{
-    RUN(test_keyset_stack);
-    RUN(test_keyset_heap);
-    RUN(test_keyset_add_remove);
-    RUN(test_keyset_lookup);
-    RUN(test_keyset_bool_ops);
-    return 0;
-}