Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualParadigm Shifter

Posted 23 April 2013 - 03:12 PM

That should do it (comparison and hash).

 

You can also store the element size and keysize when you create the hash map, then you can express the entire interface using void*, but you do lose the ability to use a literal key then (need to use a variable with an address).

 

hashmap* pMap = CreateHashSet(sizeof(int) /*keysize*/, sizeof(int) /* element size */, INT_CMP /* comparison func */. INTHASH /* hash func */);

 

int myKey = 0;

int myValue = 42;

pMap->InsertElement(&myKey, &myValue);

 

where the insert uses sizeof(int) stored as the keysize to copy the element, and InsertElement just uses void* parameters (size is known by the data associated with the map).


#1Paradigm Shifter

Posted 23 April 2013 - 03:11 PM

That should do it (comparison and hash).

 

You can also store the element size and keysize when you create the hash map, then you can express the entire interface using void*, but you do lose the ability to use a literal key then (need to use a variable with an address).

 

hashmap* pMap = CreateHashSet(sizeof(int) /*keysize*/, INT_CMP /* comparison func */. INTHASH /* hash func */);

 

int myKey = 0;

int myValue = 42;

pMap->InsertElement(&myKey, &myValue);

 

where the insert uses sizeof(int) stored as the keysize to copy the element.


PARTNERS