Browse Source

Add C set library submodule.

Stefano Cossu 5 years ago
parent
commit
f66640a3a5
5 changed files with 55 additions and 2 deletions
  1. 3 0
      .gitmodules
  2. 2 0
      MANIFEST.in
  3. 1 0
      ext/c-algorithms
  4. 40 0
      lakesuperior/cy_include/calg.pxd
  5. 9 2
      setup.py

+ 3 - 0
.gitmodules

@@ -9,3 +9,6 @@
 [submodule "ext/spookyhash"]
     path = ext/spookyhash
     url = https://github.com/centaurean/spookyhash.git
+[submodule "ext/c-algorithms"]
+    path = ext/c-algorithms
+    url = https://github.com/fragglet/c-algorithms.git

+ 2 - 0
MANIFEST.in

@@ -5,6 +5,8 @@ include ext/lmdb/libraries/liblmdb/mdb.c
 include ext/lmdb/libraries/liblmdb/lmdb.h
 include ext/lmdb/libraries/liblmdb/midl.c
 include ext/lmdb/libraries/liblmdb/midl.h
+include ext/c-algorithms/src/set.c
+include ext/c-algorithms/src/set.h
 include ext/tpl/src/tpl.c
 include ext/tpl/src/tpl.h
 include ext/spookyhash/src/*.c

+ 1 - 0
ext/c-algorithms

@@ -0,0 +1 @@
+Subproject commit 5b0555f4aa832a9d4c8662316994faa80f52ae93

+ 40 - 0
lakesuperior/cy_include/calg.pxd

@@ -0,0 +1,40 @@
+cdef extern from 'set.h':
+    #ctypedef _Set Set
+    #ctypedef _SetEntry SetEntry
+    ctypedef void *SetValue
+
+    ctypedef struct SetEntry:
+        SetValue data
+        SetEntry *next
+
+    ctypedef struct Set:
+        SetEntry **table
+        unsigned int entries
+        unsigned int table_size
+        unsigned int prime_index
+        #SetHashFunc hash_func
+        #SetEqualFunc equal_func
+        #SetFreeFunc free_func
+
+    ctypedef struct SetIterator:
+        pass
+
+    ctypedef unsigned int (*SetHashFunc)(SetValue value)
+    ctypedef bint (*SetEqualFunc)(SetValue value1, SetValue value2)
+    ctypedef void (*SetFreeFunc)(SetValue value)
+
+    Set *set_new(SetHashFunc hash_func, SetEqualFunc equal_func)
+    void set_free(Set *set)
+    # TODO This should return an int, ideally. See
+    # https://github.com/fragglet/c-algorithms/issues/20
+    bint set_insert(Set *set, SetValue data)
+    bint set_query(Set *set, SetValue data)
+    unsigned int set_num_entries(Set *set)
+    SetValue *set_to_array(Set *set)
+    Set *set_union(Set *set1, Set *set2)
+    Set *set_intersection(Set *set1, Set *set2)
+    void set_iterate(Set *set, SetIterator *iter)
+    bint set_iter_has_more(SetIterator *iterator)
+    SetValue set_iter_next(SetIterator *iterator)
+
+

+ 9 - 2
setup.py

@@ -42,11 +42,17 @@ with open(readme_fpath, encoding='utf-8') as f:
     long_description = f.read()
 
 # Extensions directory.
+calg_src_dir = path.join('ext', 'c-algorithms', 'src')
 lmdb_src_dir = path.join('ext', 'lmdb', 'libraries', 'liblmdb')
-tpl_src_dir = path.join('ext', 'tpl', 'src')
 spookyhash_src_dir = path.join('ext', 'spookyhash', 'src')
+tpl_src_dir = path.join('ext', 'tpl', 'src')
 
-include_dirs = [lmdb_src_dir, tpl_src_dir, spookyhash_src_dir]
+include_dirs = [
+    calg_src_dir,
+    lmdb_src_dir,
+    spookyhash_src_dir,
+    tpl_src_dir,
+]
 
 cy_include_dir = path.join('lakesuperior', 'cy_include')
 
@@ -105,6 +111,7 @@ extensions = [
     Extension(
         'lakesuperior.store.ldp_rs.graph',
         [
+            path.join(calg_src_dir, 'set.c'),
             path.join('lakesuperior', 'store', 'ldp_rs', f'graph.{ext}'),
         ],
         include_dirs=include_dirs,