p_table
= cluster[key_t, value_t: type] is create, lookup, insert, change, delete, empty, unparse, elements
where key_t has equal, lt: proctype(key_t,key_t) returns(bool)
- Overview
- p_table is a fast, general, parameterized table data structure. It allows values of type value_t to be stored along with a key of type key_t. These values may then be quickly looked up by their key. insert, delete, lookup, and change operations all run in O(ln N) time, where N is the number of items in the table.
- create = proc() returns(cvt)
- effects: creates a new, empty table and returns it.
- lookup = proc(tbl: cvt, key: key_t) returns(value_t) signals(not_found)
- effects: If there is an entry in tbl whose key matches "key," returns its associated value. Signals not_found if there is no entry whose key matches "key."
- insert = proc(tbl: cvt, key: key_t, val: value_t) signals(duplicate)
- modifies: tbl
- effects: Modifies tbl by inserting an entry whose key is labeled "key" and whose associated value is "val." Signals duplicate if a key labeled "key" already exists.
- change = proc(tbl: cvt, key: key_t, new_val:value_t) signals(not_found)
- modifies: tbl
- effects: Modifies tbl by changing the value associated with "key" to new_val. Signals not_found if there is no entry whose key is "key."
- delete = proc(tbl: cvt, name: key_t) signals(not_found)
- modifies: tbl
- effects: Modifies tbl by removing the entry whose key is "key." Signals not_found if there is no such entry.
- empty = proc(tbl: cvt) returns(bool)
- effects: Returns true if there are no entries in tbl, otherwise returns false.
- unparse = proc(tbl: p_table[key_t,value_t]) returns(string) where value_t has unparse: proctype(value_t) returns(string),
key_t has unparse: proctype(key_t) returns(string)
- effects: Returns a human-readable string that describes the current contents of tbl
- elements = iter(tbl: cvt) yields(key_t, value_t)
- effects: Yields each key in tbl and its associated value exactly once.