calg.pxd 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. cdef extern from 'set.h':
  2. #ctypedef _Set Set
  3. #ctypedef _SetEntry SetEntry
  4. ctypedef void *SetValue
  5. ctypedef struct SetEntry:
  6. SetValue data
  7. SetEntry *next
  8. ctypedef struct Set:
  9. SetEntry **table
  10. unsigned int entries
  11. unsigned int table_size
  12. unsigned int prime_index
  13. #SetHashFunc hash_func
  14. #SetEqualFunc equal_func
  15. #SetFreeFunc free_func
  16. ctypedef struct SetIterator:
  17. pass
  18. ctypedef unsigned int (*SetHashFunc)(SetValue value)
  19. ctypedef bint (*SetEqualFunc)(SetValue value1, SetValue value2)
  20. ctypedef void (*SetFreeFunc)(SetValue value)
  21. Set *set_new(SetHashFunc hash_func, SetEqualFunc equal_func)
  22. void set_free(Set *set)
  23. # TODO This should return an int, ideally. See
  24. # https://github.com/fragglet/c-algorithms/issues/20
  25. bint set_insert(Set *set, SetValue data)
  26. bint set_query(Set *set, SetValue data)
  27. unsigned int set_num_entries(Set *set)
  28. SetValue *set_to_array(Set *set)
  29. Set *set_union(Set *set1, Set *set2)
  30. Set *set_intersection(Set *set1, Set *set2)
  31. void set_iterate(Set *set, SetIterator *iter)
  32. bint set_iter_has_more(SetIterator *iterator)
  33. SetValue set_iter_next(SetIterator *iterator)
  34. cdef extern from 'hash-table.h':
  35. ctypedef void *HashTableKey
  36. ctypedef void *HashTableValue
  37. ctypedef struct HashTablePair:
  38. HashTableKey key
  39. HashTableKey value
  40. ctypedef struct HashTableEntry:
  41. HashTablePair pair
  42. HashTableEntry *next
  43. ctypedef struct HashTable:
  44. HashTableEntry **table
  45. unsigned int table_size
  46. unsigned int entries
  47. unsigned int prime_index
  48. ctypedef struct HashTableIterator:
  49. pass
  50. ctypedef unsigned int (*HashTableHashFunc)(HashTableKey value)
  51. ctypedef bint (*HashTableEqualFunc)(
  52. HashTableKey value1, HashTableKey value2)
  53. ctypedef void (*HashTableKeyFreeFunc)(HashTableKey value)
  54. ctypedef void (*HashTableValueFreeFunc)(HashTableValue value)
  55. HashTable *hash_table_new(
  56. HashTableHashFunc hash_func, HashTableEqualFunc equal_func)
  57. void hash_table_free(HashTable *hash_table)
  58. void hash_table_register_free_functions(
  59. HashTable *hash_table, HashTableKeyFreeFunc key_free_func,
  60. HashTableValueFreeFunc value_free_func)
  61. int hash_table_insert(
  62. HashTable *hash_table, HashTableKey key, HashTableValue value)
  63. HashTableValue hash_table_lookup(
  64. HashTable *hash_table, HashTableKey key)
  65. bint hash_table_remove(HashTable *hash_table, HashTableKey key)
  66. unsigned int hash_table_num_entries(HashTable *hash_table)
  67. void hash_table_iterate(HashTable *hash_table, HashTableIterator *iter)
  68. bint hash_table_iter_has_more(HashTableIterator *iterator)
  69. HashTablePair hash_table_iter_next(HashTableIterator *iterator)