#import <ObjectiveLib/Map.h>
Inheritance diagram for OLMap:
Public Member Functions | |
(void) | - assignKey:value: |
Assign a value to a key. | |
(OLAssociativeIterator *) | - begin |
Return an iterator that points to the first element in the map. | |
(void) | - clear |
Remove all elements. | |
(int) | - compare: |
Compare this map to another object. | |
(id) | - copy |
Make a copy of this map. | |
(unsigned) | - count: |
Return the number of instances of key in the map. | |
(BOOL) | - empty |
Return whether the map is empty. | |
(OLAssociativeIterator *) | - end |
Return an iterator that points to one position beyond the last element. | |
(OLPair *) | - equalRange: |
Return a range whose elements are equal to key. | |
(void) | - erase: |
Remove the element designated by where. | |
(void) | - eraseFrom:to: |
Remove a range of elements. | |
(unsigned) | - eraseKey: |
Erase all instances of key. | |
(OLAssociativeIterator *) | - find: |
Find an element. | |
(id) | - insert: |
Insert a key-value pair into the map. | |
(OLAssociativeIterator *) | - insertAt:value: |
Insert a key-value pair into the map. | |
(void) | - insertFrom:to: |
Insert a range of key-value pairs into the map. | |
(id) | - insertKey:value: |
Insert a key-value pair. | |
(BOOL) | - isEqual: |
Test whether another map is equal to this one. | |
(OLStreamableFunctor< OLBoolBinaryFunction > *) | - keyComp |
Return the comparison function for keys. | |
(OLAssociativeIterator *) | - lowerBound: |
Find the lower bound of a given key. | |
(unsigned) | - maxSize |
Return the maxiumum number of objects that can be stored in a map. | |
(OLReverseBidiIterator *) | - rbegin |
Return a reverse iterator pointing to the end of the sequence. | |
(OLReverseBidiIterator *) | - rend |
Return a reverse iterator pointing to the beginning of the sequence. | |
(unsigned) | - size |
Return the number of elements in the map. | |
(void) | - swap: |
Swap this map with another one. | |
(OLAssociativeIterator *) | - upperBound: |
Find the upper bound of a given key. | |
(OLStreamableFunctor< OLBoolBinaryFunction > *) | - valueComp |
Return the function used to compare values. | |
(id) | - valueForKey: |
Find the value of a given key. | |
(void) | - writeSelfToStream: |
Write the object to a stream. | |
Initializers and Deallocators | |
(id) | - free |
Finalize the map and deallocate any allocated memory. | |
(id) | - init |
Initialize the map. | |
(id) | - initFrom:to: |
Initialize the map. | |
(id) | - initFrom:to:compare: |
Initialize the map. | |
(id) | - initWithCompare: |
Initialize the map. | |
(id) | - initWithMap: |
Initialize the map. | |
(id) | - initWithObjectInStream: |
Initialize the object. | |
Static Public Member Functions | |
(id) | + map |
Create and return a new map. | |
(id) | + mapFrom:to: |
Create and return a new map. | |
(id) | + mapWithCompare: |
Create and return a new map. | |
(id) | + mapWithMap: |
Create and return a new map. | |
Protected Attributes | |
OLTreeMap * | tree |
The red-black tree that provides the underlying data structure. |
A map is a sorted associative container of elements. Keys are associated with values, and the keys can be used to look up and gain access to values. Each key is unique. If a key-value pair is inserted into the map and the key already exists, then the insertion will fail. Maps are sorted by definition and the sorting order is determined by a comparison function that is passed at initialization. If no comparison function is specified, then OLLess is used, thus sorting the map in ascending order.
The object to which a map's iterators point is an instance of OLPair. The first value of the pair is the key, and the second value of the pair is the key's value.
- (void) assignKey: | (id) | key | ||
value: | (id) | value | ||
Assign a value to a key.
If the key exists in the map, then value is assigned to the key and the old value is dropped. If the key does not exist in the map, then the key-value pair is inserted.
key | the key to which to assign | |
value | the value to assign |
Reimplemented in OLMultiMap.
- (OLAssociativeIterator*) begin |
Return an iterator that points to the first element in the map.
The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
- (void) clear |
Remove all elements.
- (int) compare: | (id) | other |
Compare this map to another object.
If the other object is of type OLMap, each of the contained objects is compared to the corresponding object in other by calling the compare:
method.
other | the object with which to compare this one |
- (id) copy |
Make a copy of this map.
- (unsigned) count: | (id) | key |
Return the number of instances of key in the map.
key | the key for which to search |
- (BOOL) empty |
Return whether the map is empty.
- (OLAssociativeIterator*) end |
Return an iterator that points to one position beyond the last element.
The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
- (OLPair*) equalRange: | (id) | key |
Return a range whose elements are equal to key.
The returned pair contains two instances of OLAssociativeIterator delimiting the range of elements. The objects to which the iterators point are instances of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
key | the value for which to search |
- (void) erase: | (OLAssociativeIterator *) | where |
Remove the element designated by where.
where | an iterator designating the element to remove |
- (void) eraseFrom: | (OLAssociativeIterator *) | first | ||
to: | (OLAssociativeIterator *) | last | ||
Remove a range of elements.
All elements in the range [first, last)
will be removed from the map.
first | the first in the range of elements to remove | |
last | one position beyond the last in the range of elements to remove |
- (unsigned) eraseKey: | (id) | key |
Erase all instances of key.
The map is searched for key, all instances are removed from the map and the number removed is returned.
key | the key to remove from the map |
- (OLAssociativeIterator*) find: | (id) | key |
Find an element.
The element key is searched for in the map and an iterator to its location is returned. If the element does not exist in the map, then the returned iterator will be equal to the iterator returned by end.
The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
key | the key for which to search |
- (id) free |
Finalize the map and deallocate any allocated memory.
- (id) init |
Initialize the map.
The map is empty and OLLess is used as the comparison function.
- (id) initFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
Initialize the map.
All elements in the range [first, last)
are inserted into the map. OLLess is used as the comparison function. If any duplicate keys exist in the range [first, last)
, then only the first instance is inserted.
[first, last)
must be an instance of OLPair. The first element of the pair is the key and the second element is the key's value.first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert |
- (id) initFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
compare: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | comp | ||
Initialize the map.
All elements in the range [first, last)
are inserted into the map. The comparison function comp is used.
[first, last)
must be an instance of OLPair. The first element of the pair is the key and the second element is the key's value.first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert | |
comp | the comparison function used to sort keys |
- (id) initWithCompare: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | comp |
Initialize the map.
The map is empty and the comparison function comp is used to sort keys.
comp | the comparison function used to sort keys |
- (id) initWithMap: | (OLMap *) | right |
Initialize the map.
The comparison function and all elements are copied from right into this map.
right | the map with which to initialize this one |
- (id) initWithObjectInStream: | (OLObjectInStream *) | stream |
Initialize the object.
Each instance variable is read from stream and all other initialization is performed.
stream | the stream from which to read |
Reimplemented from < OLStreamable >.
- (id) insert: | (OLPair *) | keyValue |
Insert a key-value pair into the map.
An attempt is made to insert keyValue into the map, and an instance of OLPair is returned indicating the state of the insertion. The first element in the returned pair is an instance of OLAssociativeIterator indicating the position of keyValue in the map, and the second element of the returned pair is an object that responds to the message boolValue
. The message boolValue
will return YES if the insertion was successful, or NO if not.
keyValue | the key-value pair to insert |
Reimplemented in OLMultiMap.
- (OLAssociativeIterator*) insertAt: | (OLAssociativeIterator *) | where | ||
value: | (OLPair *) | keyVal | ||
Insert a key-value pair into the map.
The keyVal is inserted and the position indicated by where is used as a hint about where in the map the keyVal should be placed. There is no guarantee that the keyVal will ultimately placed anywhere close to where. Note that the insertion may fail if the key is already in the map. An iterator is returned that points to object. The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
where | a hint as to where in the map the keyVal should be located | |
keyVal | the key-value pair to insert |
Reimplemented in OLMultiMap.
- (void) insertFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
Insert a range of key-value pairs into the map.
An attempt is made to insert all pairs in the range [first, last)
, however there is no guarantee that any of the elements in the range will actually be inserted if they already exist in the map.
[first, last)
must be instances of OLPair where the first element of the pair is the key and the second element is the key's value.first | the first in the range of pairs to insert | |
last | one position beyond the last in the range of pairs to insert |
Reimplemented in OLMultiMap.
- (id) insertKey: | (id) | key | ||
value: | (id) | val | ||
Insert a key-value pair.
This message is simply a wrapper for insert:, provided as a convenience. It elminiates the need to create an instance of OLPair before performing insertion. As with insert: the message returns an instance of OLPair indicating the state of the insertion. The first element of the pair returned is an instance of OLAssociativeIterator indicating the position of key in the map, and the second element of the pair is an object that responds to the message boolValue
. The message boolValue
will return YES if the insertion succeeded, or NO if it did not.
key | the key to insert | |
val | the value of the key |
- (BOOL) isEqual: | (id) | object |
Test whether another map is equal to this one.
Two maps are considered equal if they contain the same number of objects and the objects are in the same order and each object is equal to the corresponding object in the other map.
object | the object to test |
Reimplemented from < OLInserter >.
Reimplemented in OLMultiMap.
- (OLStreamableFunctor<OLBoolBinaryFunction>*) keyComp |
Return the comparison function for keys.
This function ultimately determines the sorting order of the map.
- (OLAssociativeIterator*) lowerBound: | (id) | key |
Find the lower bound of a given key.
The lower bound is the first position in the map at which key can be inserted without disturbing the sorting order. An iterator pointing to the lower bound is returned. The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
key | the key for which to find the lower bound |
+ (id) map |
Create and return a new map.
An instance of OLLess is used to compare keys for sorting.
+ (id) mapFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
Create and return a new map.
The map is initialized with the contents of the range [first, last)
. An instance of OLLess is used to compare keys for sorting.
[first, last)
must be an instance of OLPair. The first element of the pair is the key and the second element is the key's value.first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert |
+ (id) mapWithCompare: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | comp |
Create and return a new map.
The map is empty and the comparison function comp is used to sort keys.
comp | the comparison function used to sort keys |
+ (id) mapWithMap: | (OLMap *) | right |
Create and return a new map.
The map is initialized with the contents of right.
right | the map to copy |
- (unsigned) maxSize |
Return the maxiumum number of objects that can be stored in a map.
This limit is theoretical, meaning that there is no guarantee that you can insert this many objects into any given map. The memory conditions of the run-time system play an important role.
- (OLReverseBidiIterator*) rbegin |
Return a reverse iterator pointing to the end of the sequence.
Advancing the returned iterator will move backwards through the sequence to the point indicated by the iterator returned by rend. The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
- (OLReverseBidiIterator*) rend |
Return a reverse iterator pointing to the beginning of the sequence.
This iterator indicates one position beyond the last position that may be referenced by a reverse iterator. The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
- (unsigned) size |
Return the number of elements in the map.
- (void) swap: | (OLMap *) | right |
Swap this map with another one.
All elements in right will be placed into this map, and all elements in this map will be placed in right.
right | the map with which to swap this one |
- (OLAssociativeIterator*) upperBound: | (id) | key |
Find the upper bound of a given key.
The upper bound is the last position in the map at which key can be inserted without disturbing the sorting order. An iterator pointing to the upper bound is returned. The object to which the iterator points is an instance of OLPair. The first element of the pair is the key and the second element of the pair is the key's value.
key | the key for which to find the upper bound |
- (OLStreamableFunctor<OLBoolBinaryFunction>*) valueComp |
Return the function used to compare values.
This returns the same function as the message keyComp.
- (id) valueForKey: | (id) | key |
Find the value of a given key.
The map is searched for key, and if it is found its value is returned. Otherwise, the message returns nil
.
key | the key for which to search |
nil
if the key does not exist in the map Reimplemented in OLMultiMap.
- (void) writeSelfToStream: | (OLObjectOutStream *) | stream |
Write the object to a stream.
All instance variables are written to stream.
stream | the stream to which to write. |
Reimplemented from < OLStreamable >.
- (OLTreeMap*) tree [protected] |
The red-black tree that provides the underlying data structure.
|