This library is one of the most essential ones of LibertyEiffel. It is generally used along with lib/abilities because some classes require specific properties about objects they can contain. Most of the storage classes are also TRAVERSABLE, and also supply ITERATOR objects (see the lib/iterator library).
The point here is to store objects. This implies not only to "remember" them, but also to "retrieve" them, of course. But everything is based on the way to retrieve a stored object.
Collections are classes that allow to store objects and recover them by using integers. The two most known implementations are available: arrays (contiguous storage of elements) and linked lists (storage of elements with references to other elements).
The most useful classes are:
- ARRAY, the well-known array
- RING_ARRAY, an array whose implementation is optimized for extensions at both ends
- FAST_ARRAY, an array whose lower bound is always 0
- LINKED_LIST and TWO_WAY_LINKED_LIST are linked lists
Dictionaries are classes that allow to store key-value couples. Thus a value is available with its key.
One can say that collections are equivalent to dictionaries whose keys are integers, but the case of collections is kept because it is very frequent.
There are several dictionary implementations, that use different properties of the keys to accelerate access to the elements without having to look through the whole dictionary.
- If the keys are HASHABLE, one can use the HASHED_DICTIONARY class that uses the hash_code of the keys.
- If the keys are COMPARABLE, one can use the AVL_DICTIONARY class that uses a balanced binary tree.
- There is no implementation if the keys have none of these two properties.
One will notice the bijective dictionaries whose elements are all unique. One can also define an inverted bijective dictionary (planned class for the version 2.3).
Sets are classes that allow to store elements in a unique manner. The goal is not necessarily to retrieve them by a key, but to know how to look through the set of elements.
As with dictionaries, there are two kinds of sets in accordance with the properties of the elements.
- If the elements are HASHABLE, one can use the HASHED_SET classe that uses the hash_code of the elements.
- If the elements are COMPARABLE, one can use the AVL_SET class that uses a balanced binary tree.
- There is no implementation if the elements have none of these two properties.
MULTI_SETs are not yet implemented.
Queues and stacks
The QUEUE class implements queues of objects.
The STACK class implements stacks of objects.
Repositories allow to store objects so as to retrieve them later. The point here is to serialize objects. This is useful, for example, to store objects on the hard drive (by using lib/io), or to transmit them on the network (by using lib/net), etc.
These repositories behave like dictionaries whose keys are strings and values are STORABLE. Their interface is similar to the one of the dictionaries, with additional features to load objects (update) and store them (commit).