Reference Guide C API www.spreadconcepts.com


C API
Replicated Hash Table
Version 2.0


rht_key_cmp_fcn
  int rht_key_cmp_fcn(rht_blob k1, rht_blob k2, const void *kcntxt);


Parameters
  k1 first key to compare
  k2 second key to compare with the first key
  kcntxt user context


Return Values
  0 on k1 equal to k2
  <1 on k1 less than k2
  > 1 on k1 greater than k2


Description
 

User defined comparison function called when two keys need to be compared.
There are several important issues to consider when constructing key comparison functions:

  • Your key_cmp relation must return zero if two keys are considered equivalent and non-zero if they are not.
  • Your key_cmp relation must be invariant, reflexive, symmetric and transitive.
  • You must ensure that key_cntxt remains valid for your key comparison functions during the lifetime (described below -- see on_trash_cb) of this replica. An easy way to accomplish this is to have any such context be allocated and initialized on program startup and never deallocated (e.g. - static allocation).
  • You must account for any endian differences amongst the replicant host machines. For example, if your key comparison functions consider endian dependent information (such as an int or a float) and your RHT network involves different endianness architectures, then you must always insert your keys in a consistent form (e.g. - network endian form) and your comparison functions will need to convert that information to a locally appropriate representation before comparing.

Additionally, for ordered dictionaries (coming soon):

  • Your key_cmp function must return an integer less than, equal to, or greater than zero if the first key is considered, respectively, to be less than, to be equivalent to or to be greater than the second key. For unordered dictionaries:
  • Your key_hcode mapping must be an invariant mapping from keys to the integer range [-2^31, 2^31). Any predictable structure in the mapping will be removed by the dictionary (i.e. - it is OK if your mapping exhibits strong structure; for example such as mapping all keys of a certain type only to even integers).
  • For best performance, a random key should have approximately 1 / 2^32 probability of mapping to any given value.
  • Your key_cmp relation and key_hcode mapping must be equality compatible: [key_cmp(key1, key2) == 0 => key_hcode(key1) == key_hcode(key2)]. Note that the reverse implication need not be true.


Requirements
  Header: Declared in rht.h
Library: Use rht.lib
Version: 2.0


Also See
  RHT reference guide, key_hcode_fnc, callback functions


Copyright © 2004, Spread Concepts LLC, All rights reserved