class table
This is the built-in table class.
Global Functions
table merge (const table, const table, table::merger) | Merges the given tables according to the specified delegate and returns a new table. |
Constructors
table () | Constructs a new, empty hashtable. |
table (const table) | Copy constructs a new table from the specified one. |
table (const var[]) | Constructs a new table from the specified array. |
table (const list) | Constructs a new table from the specified list. |
Methods
int cleanup () | Frees all empty nodes in this table, releasing unneeded resources. |
table deepCopy () | Returns a deep-copy of this table. |
enumerate (array::enumerator, var) | Calls the specified enumerator delegate for every value in this table. |
var get (const string) | Retrieves a value from the table by the specified key. |
set (const string, var) | Stores a value in the table under the specified key. |
var[] toArray () | Moves all values from this table into a new array. |
list toList () | Moves all keys and values from this table into a new list. |
Reference
function table merge (const table t1, const table t2, table::merger fn) |
Merges the given tables according to the specified delegate and returns a new table. The function works as follows: First a reference table is created that contains all keys from both tables, but not their values. Then the reference table is iterated recursively. For every key in the reference table, the table::merger delegate is called. The current key, both source tables and a result table are passed to the delegate. The delegate defines how values from either or both source tables are stored in the result table. |
method table () |
Constructs a new, empty hashtable. |
method table (const table) |
Copy constructs a new table from the specified one. The new table will be a shallow-copy, meaning values in the table will only be copied by reference. |
method table (const var[]) |
Constructs a new table from the specified array. The array is expected to be one-dimensional and have the following format: Every even element must be a string and is considered a key. Every odd element can be of any type and is considered a value. |
method table (const list) |
Constructs a new table from the specified list. The list's items will be added to the table by their keys, so keys should be unique for every item in the list. If the keys are not strings, they will be converted to strings by this function. |
method int cleanup () |
Frees all empty nodes in this table, releasing unneeded resources. This only affects internal infrastructure, all table data will remain intact. When storing and clearing large amounts of values in the table, calling this can improve memory footprint and performance of all other recursive table methods. |
method table deepCopy () |
Returns a deep-copy of this table. WARNING: All table data will be copied! This is a highly recursive operation. If the table contains script objects that have copy-constructors, this method can be very time consuming. It should only be called in cases where a shallow copy would not suffice. |
method enumerate (array::enumerator fn, var args) |
Calls the specified enumerator delegate for every value in this table. This is a highly recursive operation that can be very time consuming with large tables. |
method var get (const string key) |
Retrieves a value from the table by the specified key. If no value exists in the table under the specified key, null is returned. |
method set (const string key, var value) |
Stores a value in the table under the specified key. If a value already exists under this key, it is overwritten. To clear a value in the table, you can just set it to null. |
method var[] toArray () |
Moves all values from this table into a new array. This is a highly recursive operation that can be very time consuming with complex tables. |
method list toList () |
Moves all keys and values from this table into a new list. This is a highly recursive operation that can be very time consuming with complex tables. |