A hash stores a number of objects, which can be accessed by a named key.
Parameters: LandHash * self
Returns: int
Returns: LandHashIterator
Parameters: LandHash * self, LandHashIterator * i
Returns: void*
Returns: bool
Parameters: char const * f, int l
Returns: LandHash*
Parameters: LandHash * self, char const * f, int l
no parameters
Create a new LandHash.
Clears the hash. Referenced data are not touched though.
Destroy a LandHash. The data inside the hash are not freed (just everything else, like key names and internal data structures).
Parameters: LandHash * self, char const * thekey, void * data
Insert data into a LandHash.
A LandHash simply is a mapping of keys to data pointers - it will never touch the passed data in any way. E.g. you need to make sure to delete any pointers you add to a hash. A copy of the passed key is made so you need not keep it around. If the key already exists, there will be two entries with the same key from now on, and it is undefined behavior which one will get returned when querying for the key.
Parameters: LandHash * self, char const * thekey
Remove the first entry found with the key, and return the associated data.
The returned pointer might need to be destroyed after you remove it from the hash, if it has no more use.
If an association to the given key exists, replace it with the given data, and return the old data. Else, do the same as land_hash_insert, and return None.
Return the data associated with a hash key. If the key exists multiple times, it can be not relied on a certain one being returned. It might always be the same, but it might not be - this is especially true if other entries are added which could lead to a re-hashing when it gets too full.
If the key is not found, None is returned.
Parameters: LandHash * hash, bool alloc
Returns: LandArray*
Return an array containing all the keys in the hash.
If alloc is true, each key is allocated and must be freed. A convenient way is to use land_array_destroy_with_strings. Otherwise the strings are direct pointers into the hash - so you must not modify or free them, and they will get invalid if the hash is modifed (even just by adding/removing an unrelated key). You are responsible for destroying the array with land_array_destroy when you are done using it.
Parameters: LandHash * hash
Return an array with all the data pointers in the hash. If you want to destroy a hash including all its data, this may be a convenient way to do it:
LandArray *data = land_hash_data(hash) for int i = 0 while i < land_array_count(data) with i++: void *entry = land_array_get_nth(data, i) land_free(entry) land_array_destroy(data) land_hash_destroy(hash)
This is an internal function for debugging purposes, which will print out statistics about the hash to the console.