![]() |
genspect::table —
class table { public: // construct/copy/destruct table(unsigned int, unsigned int); ~table(); // public member functions void reset(); void put(aterm, aterm); aterm get(aterm); void remove(aterm); aterm_list table_keys(); };
table(unsigned int initial_size, unsigned int max_load_pct);
Create an table. This function creates an table given an initial size and a maximum load percentage. Whenever this percentage is exceeded (which is detected when a new entry is added using table_put), the table is automatically expanded and all existing entries are rehashed into the new table. If you know in advance approximately how many items will be in the table, you may set it up in such a way that no resizing (and thus no rehashing) is necessary. For example, if you expect about 1000 items in the table, you can create it with its initial size set to 1333 and a maximum load percentage of 75%. You are not required to do this, it merely saves a runtime expansion and rehashing of the table which increases efficiency.
~table();
Destroy an table. Contrary to aterm_dictionaries, aterm_tables are themselves not aterms. This means they are not freed by the garbage collector when they are no longer referred to. Therefore, when the table is no longer needed, the user should release the resources allocated by the table by calling table_destroy. All references the table has to aterms will then also be removed, so that those may be freed by the garbage collector (if no other references to them exist of course).
void reset();
Reset an table. This function resets an ermtable, without freeing the memory it occupies. Its effect is the same as the subsequent execution of a destroy and a create of a table, but as no memory is released and obtained from the C memeory management system this function is gen- erally cheaper. but if subsequent tables differ very much in size, the use of table_destroy and table_create may be prefered, because in such a way the sizes of the table adapt automatically to the requirements of the application.
void put(aterm key, aterm value);
Add / update a (key, value)-pair in a table. If key does not already exist in the table, this function adds the (key, value)-pair to the table. Otherwise, it updates the value to value.
aterm get(aterm key);
Get the value belonging to a given key in a table.
void remove(aterm key);
Remove the (key, value)-pair from table.
aterm_list table_keys();
Get an aterm_list of all the keys in a table. This function can be useful if you need to iterate over all elements in a table. It returns an aterm_list containing all the keys in the table. The corresponding values of each key you are interested in can then be retrieved through respective calls to table_get.
Copyright © 2004 Wieger Wesselink |