hash_table implementation returns -1 from getBytes(), violating the API contract #62

Closed
opened 2026-07-05 01:14:13 +00:00 by weaselbot · 1 comment
Member

The hash_table shared-library implementation returns -1 from ConflictSet::getBytes() and ConflictSet_getBytes(), which contradicts the API contract documented in include/ConflictSet.h that the function "Returns the total bytes in use by this ConflictSet".

Location

  • HashTable.cpp:99int64_t ConflictSet::getBytes() const { return -1; }
  • HashTable.cpp:163-166ConflictSet_getBytes also hard-codes -1.

Reproduction

  1. Build the hash_table target:
    cmake --build build --target hash_table
    
  2. Compile and run a small C program linked against build/hash_table/libconflict-set.so:
    #include "ConflictSet.h"
    #include <stdio.h>
    
    int main(void) {
        ConflictSet *cs = ConflictSet_create(0);
        ConflictSet_WriteRange w = {{(const uint8_t *)"0000", 4}, {NULL, 0}};
        ConflictSet_addWrites(cs, &w, 1, 1);
        int64_t bytes = ConflictSet_getBytes(cs);
        printf("%ld\n", bytes);
        ConflictSet_destroy(cs);
        return 0;
    }
    
  3. Actual output:
    -1
    

Expected behavior

getBytes() should return a non-negative value representing the memory in use by the hash table implementation, consistent with the radix tree and skip list implementations. If tracking memory is intentionally not supported, the function should at least return 0 and the exception should be documented; returning -1 is not a valid byte count and violates the documented contract.

Impact

  • Any user code or binding (e.g. the Python wrapper) that loads the hash_table implementation and checks cs.getBytes() > 0 will incorrectly conclude the conflict set is empty.
  • The returned value is silently incompatible with the documented semantics, making the hash_table implementation non-interchangeable with the other implementations for callers that inspect memory usage.
The `hash_table` shared-library implementation returns `-1` from `ConflictSet::getBytes()` and `ConflictSet_getBytes()`, which contradicts the API contract documented in `include/ConflictSet.h` that the function "Returns the total bytes in use by this ConflictSet". ## Location - `HashTable.cpp:99` — `int64_t ConflictSet::getBytes() const { return -1; }` - `HashTable.cpp:163-166` — `ConflictSet_getBytes` also hard-codes `-1`. ## Reproduction 1. Build the hash_table target: ```sh cmake --build build --target hash_table ``` 2. Compile and run a small C program linked against `build/hash_table/libconflict-set.so`: ```c #include "ConflictSet.h" #include <stdio.h> int main(void) { ConflictSet *cs = ConflictSet_create(0); ConflictSet_WriteRange w = {{(const uint8_t *)"0000", 4}, {NULL, 0}}; ConflictSet_addWrites(cs, &w, 1, 1); int64_t bytes = ConflictSet_getBytes(cs); printf("%ld\n", bytes); ConflictSet_destroy(cs); return 0; } ``` 3. Actual output: ``` -1 ``` ## Expected behavior `getBytes()` should return a non-negative value representing the memory in use by the hash table implementation, consistent with the radix tree and skip list implementations. If tracking memory is intentionally not supported, the function should at least return `0` and the exception should be documented; returning `-1` is not a valid byte count and violates the documented contract. ## Impact - Any user code or binding (e.g. the Python wrapper) that loads the `hash_table` implementation and checks `cs.getBytes() > 0` will incorrectly conclude the conflict set is empty. - The returned value is silently incompatible with the documented semantics, making the hash_table implementation non-interchangeable with the other implementations for callers that inspect memory usage.
Owner

Hash table is test only and does not satisfy the contract. It’s for comparing how fast point ops could be. Returning 0 for bytes used seems ok too

Hash table is test only and does not satisfy the contract. It’s for comparing how fast point ops could be. Returning 0 for bytes used seems ok too
weaselbot was assigned by andrew 2026-07-05 04:35:29 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/conflict-set#62