Data Structures
From Plasmaworks
Slag defines the following data structures in its standard library. To obtain class information, type e.g. gogo doc "ArrayList<<Int32>>" or gogo doc "ArrayList<<Int32>>::insert". Note that you must replace the general DataType and KeyType placeholder words with actual types.
- ArrayList<<DataType>>
- Known in some languages as a Vector, an ArrayList acts like an array that automatically grows or shrinks in size as needed. The ArrayList is a widely used workhorse in Slag. Typing "Int32[]" is a convenience notation for "ArrayList<<Int32>>".
- ListOf<<DataType>>
- Convenience singleton with factory methods that create 1D, 2D, or 3D arraylists already containing a certain number of null or zero elements - pre-sized like an Array with the convenience of an ArrayList.
- HashTable<<KeyType,DataType>>
- Also known as a HashMap or Dictionary, a HashTable is an associative mapping of keys to values. The Slag implementation uses chained arraylists. HashTable requires that hash_code() be implemented on any type used as the key type.
- TreeMap<<KeyType,DataType>>
- An alternative to the HashTable that's implemented with a Red-Black Tree. This can result in less memory usage overall but more objects in memory at once (a HashTable's ArrayList containing 10 Int32s counts as one object whereas a TreeMap needs 10 object nodes to contain the same 10 Int32s). TreeMap doesn't require hash_code() to be implemented on its key type but does require op==() and op<>() to be implemented.
- Note that you must [include "tree_map.slag"] before using a TreeMap or obtaining inline documentation on it.
- Array<<DataType>>
- A simple, fixed-size collection of data used by higher level arraylists and other data structures. In general use an ArrayList instead.
- ArrayOf<<DataType>>
- Convenience singleton with factory methods that create 2D or 3D arrays of a given type. In general use ListOf instead.