Multimap Help


A multimap is almost the same as a map data structure, but in a multimap you can store multiple values per key. For example, in a student enrollment system, where students may be enrolled in multiple classes simultaneously, there might be an association for each enrollment of a student in a course, where the key is the student ID and the value is the course ID. If a student is enrolled in three courses, there will be three associations containing the same key. Multimaps maintain such groups, sorted by key. You can add pairs to the multimap and search for the values corresponding to certain keys. Because the keys are sorted you can also find previous and next keys.

Functions:

ds_multimap_create() Creates a new multimap. The function returns an integer as an id that must be used in all other functions to access the particular multimap.
ds_multimap_destroy(id) Destroys the multimap with the given id, freeing the memory used. Don't forget to call this function when you are ready with the structure.
ds_multimap_clear(id) Clears the multimap with the given id, removing all data from it but not destroying it.
ds_multimap_copy(id,source) Copies the multimap source into the multimap with the given id.
ds_multimap_copy_key(id,key,sourceid,sourcekey) Copies the multimap key source into a, possibly new, key in the multimap with the given id.
ds_multimap_size(id) Returns the total number of values stored in the multimap.
ds_multimap_empty(id) Returns whether the multimap is empty. This is the same as testing whether the size is 0.
ds_multimap_count(id,key) Returns the number of keys stored in the map.
ds_multimap_add(id,key,value) Associates a new value with a, possibly new, key in the multimap.
ds_multimap_insert(id,key,pos,value) Inserts a new value at position pos corresponding with the key in the multimap.
ds_multimap_replace(id,key,pos,value) Replaces the value at position pos corresponding with the key with a new value.
ds_multimap_replace_key(id,key,value) Replaces all values associated with the key with one new value.
ds_multimap_delete(id,key,pos) Deletes the value at position pos corresponding with the key from the multimap.
ds_multimap_delete_key(id,key) Deletes the key and all the corresponding values from the multimap.
ds_multimap_exists(id,key,value) Returns whether a value corresponding with the key exists in the multimap.
ds_multimap_exists_key(id,key) Returns whether the key exists in the multimap.
ds_multimap_number(id,key) Returns the number of values associated with the key.
ds_multimap_find_value(id,key,pos) Returns the value at position pos corresponding to the key.
ds_multimap_find_index(id,key,value) Finds the position storing the indicated value corresponding with the key. If no such value corresponds with that key -1 is returned.
ds_multimap_find_previous(id,key) Returns the largest key in the multimap smaller than the indicated key.
ds_multimap_find_next(id,key) Returns the smallest key in the multimap larger than the indicated key.
ds_multimap_find_first(id) Returns the smallest key in the multimap.
ds_multimap_find_last(id) Returns the largest key in the multimap.
ds_multimap_add_list(id,key,listid) Associates all values of a ds_list with a, possibly new, key in the multimap.
ds_multimap_get_list(id,key) Returns a ds_list containing all values associated with the key.
ds_multimap_write(id) Turns the data structure into a string and returns this string. The string can then be used to e.g. save it to a file.
ds_multimap_read(id,str) Reads the data structure from the given string (as created by the previous call).