SophiaFramework UNIVERSE 5.3 |
SFXFlatHashMap is a hashmap class whose key elements are unorderd.
Each key element of the SFXFlatHashMap instance(hashmap) needs to be data not more than 4 byte, the SFXAnsiString instance, or the SFXWideString instance. In order to process data more than 4 byte(such as UInt64 type, Float64 type, and so on) or the class instance as the value element of the SFXFlatHashMap instance(hashmap), a pointer should be used.
Speed performance of Set/Remove/Clear is superior than those of SFXLinkedHashMap and SFXOldHashmap, because all elements instances are allocated into one hash table in advance. However, if the key is SFXAnsiString class or SFXWideString class, other heaps for string will be allocated by elements.
If the element occupancy rate for the hash table exceeds DEFAULT_THRESHOLD (45) %, the size of the hash table will be automatically expanded.
// data more than 4 byte or class instance cannot be a value element of the SFXFlatHashMap instance ( hashmap ) // SFXFlatHashMap<SFXAnsiString, SInt64> map64; NG // SFXFlatHashMap<SFXAnsiString, SFXAnsiString> mapstr; NG // but a pointer to the data more than 4 byte or class instance can be a value element of the SFXFlatHashMap instance ( hashmap ) SFXFlatHashMap<SFXAnsiString, SInt64Ptr> map64; // OK SFXFlatHashMap<<SFXAnsiString, SFXAnsiStringPtr> mapstr; // OK
SFXLinkedHashMap | SFXHashmap | SFXAnsiString | SFXWideString | Hashmap
Constructor/Destructor |
---|
SFXFlatHashMap( Void ) Constructor of the SFXFlatHashMap class.
|
Public Functions | |
---|---|
Void |
Clear( Void ) Clear this hashmap.
|
Bool |
ContainsKey(
KeyType key
) Check whether or not this hashmap contains the specified key as the key of the pair element.
|
Bool |
ContainsValue(
ValueType value
) Check whether or not this hashmap contains the specified value as the value of the pair element.
|
static SFXFlatHashMap< K, V > const & |
EmptyInstance( Void ) Get the empty hashmap.
|
Bool |
Equals(
SFXFlatHashMap< K, V > const & collection
) Check whether or not this hashmap equals the specified hashmap.
|
ValueType |
Get(
KeyType key
, BoolPtr found = null
) Get the value of the key-value pair with the specified key from this hashmap.
|
KeyEnumerator |
GetKeyEnumerator( Void ) Get the key enumerator of this hashmap.
|
KeyIterator |
GetKeyIterator( Void ) Get the key iterator of this hashmap.
|
SInt32 |
GetSize( Void ) Get the size of this hashmap.
|
ValueEnumerator |
GetValueEnumerator( Void ) Get the value enumerator of this hashmap.
|
ValueIterator |
GetValueIterator( Void ) Get the value iterator of this hashmap.
|
Bool |
IsEmpty( Void ) Check whether or not this hashmap is empty.
|
SFCError |
Merge(
SFXFlatHashMap< K, V > const & collection
) Merge this hashmap with the specified hashmap.
|
Void |
Remove(
KeyType key
) Remove the key-value pair with the specified key from this hashmap.
|
SFCError |
Set(
SFXFlatHashMap< K, V > const & collection
) Set the specified key-value pair or hashmap into this hashmap.
|
SFCError |
Set(
KeyType key
, ValueType value
) Set the specified key-value pair or hashmap into this hashmap.
|
SFCError |
Swap(
KeyType destination
, KeyType source
) Swap the value of two pair elements with the specified keys.
|
ValueType |
operator[](
KeyType key
) Get the value of the key-value pair with the specified key index from this hashmap.
|
Types |
---|
DefaultEnum Default value of threshold to expand the hash table.
|
KeyEnumerator Class for managing the key enumerator for the keys of the pair elements of this hashmap.
|
KeyIterator Class for managing the key iterator for the keys of the pair elements of this hashmap.
|
ValueEnumerator Class for managing the value enumerator for the values of the pair elements of this hashmap.
|
ValueIterator Class for managing the value iterator for the values of the pair elements of this hashmap.
|
[ public, explicit ] SFXFlatHashMap(Void);
[ public ] Void Clear(Void);
This function clears this hashmap. All the internal buffer allocated to this hashmap will be released.
After this function is executed, the size of this hashmap will become 0.
If the key is a string(SFXAnsiString / SFXWideString), the string itself will be released automatically.
Caution | |
---|---|
If the type of the key or the value of the pair element is a pointer to a class instance or data bigger than 4 bytes, memory area that the pointer points to will not be released automatically. Before clearing this hashmap, it is necessary to release that area explicitly using the delete statement. Otherwise, memory leakage will occur. |
Note | |
---|---|
This function will be called automatically when this hashmap goes out of scope. |
SFXFlatHashMap<SFXAnsiString, SInt32> strmap;
...
strmap.Clear(); // clear the hashmap
[ public, const ] Bool ContainsKey( KeyType key // key to check );
This function checks whether or not this hashmap contains the specified key as the key of the pair element.
Note | |
---|---|
If the type of the element is a pointer to a class instance or data bigger than 4 bytes, their addresses will be compared with. |
SFXFlatHashMap<SFXAnsiString, SInt32> strmap; // set a key-value pair element of (key: "mike", value: 2) into the hashmap if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a key-value pair element of (key: "john", value: 1) into the hashmap if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // check whether or not the hashmap contains the keys below TRACE("ContainsKey(\"mike\") = %s", (strmap.ContainsKey("mike")) ? ("true") : ("false")); // containsKey("mike") = true TRACE("ContainsKey(\"tom\") = %s", (strmap.ContainsKey("tom")) ? ("true") : ("false")); // containsKey("tom") = false } }
[ public, const ] Bool ContainsValue( ValueType value // value to check );
This function checks whether or not this hashmap contains the specified value as the value of the pair element.
Note | |
---|---|
If the type of the element is a pointer to a class instance or data bigger than 4 bytes, their addresses will be compared with. |
SFXFlatHashMap<SFXAnsiString, SInt32> strmap; // set a key-value pair element of (key: "mike", value: 2) into the hashmap if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a key-value pair element of (key: "john", value: 1) into the hashmap if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // check whether or not the hashmap contains the values below TRACE("ContainsValue(2) = %s", (strmap.ContainsValue(2)) ? ("true") : ("false")); // containsValue(2) = true TRACE("ContainsValue(5) = %s", (strmap.ContainsValue(5)) ? ("true") : ("false")); // containsValue(5) = false } }
[ public, static ] SFXFlatHashMap< K, V > const & EmptyInstance(Void);
Empty hashmap
This function gets the empty hashmap.
[ public, const ] Bool Equals( SFXFlatHashMap< K, V > const & collection // hashmap to compare with );
This function checks whether or not this hashmap equals the specified hashmap.
Note | |
---|---|
If the type of the element is a pointer, its address will be compared with. |
[ public, const ] ValueType Get( KeyType key // key to get the value element BoolPtr found = null // whether the key exists (optional) );
If there is the key-value pair with the specified key in this hashmap, the corresponding value will be returned.
Otherwise, null or 0 will be returned.
This function gets the value of the key-value pair with the specified key from this hashmap.
When a key-value pair with the specified key exists, the second parameter "found" is set to true. Otherwise, false.
Caution | |
---|---|
In case no key-value pair with the specified key exists, no error will occur but this function will return 0 or null. |
SFXFlatHashMap<SFXAnsiString, SInt32> strmap; // set a key-value pair element of (key: "mike", value: 2) into the hashmap if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a key-value pair element of (key: "john", value: 1) into the hashmap if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // display the value of the key-value pair with the specified key in BREW Output Window TRACE("%d", strmap.Get("mike")); // 2 } }
[ public, const ] KeyEnumerator GetKeyEnumerator(Void);
Key enumerator of this hashmap.
This function gets the key enumerator of this hashmap.
SFXFlatHashMap::GetKeyIterator | SFXFlatHashMap::GetValueIterator | SFXFlatHashMap::GetValueEnumerator | SFXFlatHashMap::ValueEnumerator | SFXFlatHashMap::ValueIterator | SFXFlatHashMap::KeyEnumerator | SFXFlatHashMap::KeyIterator
[ public ] KeyIterator GetKeyIterator(Void);
Key iterator of this hashmap.
This function gets the key iterator of this hashmap.
SFXFlatHashMap::GetKeyEnumerator | SFXFlatHashMap::GetValueEnumerator | SFXFlatHashMap::GetValueIterator | SFXFlatHashMap::ValueEnumerator | SFXFlatHashMap::ValueIterator | SFXFlatHashMap::KeyEnumerator | SFXFlatHashMap::KeyIterator
[ public, const ] SInt32 GetSize(Void);
Size of this hashmap
This function gets the size of this hashmap(i.e., the number of the key-value pair elements of this hashmap).
[ public, const ] ValueEnumerator GetValueEnumerator(Void);
Value enumerator of this hashmap.
This function gets the value enumerator of this hashmap.
SFXFlatHashMap::GetValueIterator | SFXFlatHashMap::GetKeyIterator | SFXFlatHashMap::GetKeyEnumerator | SFXFlatHashMap::ValueEnumerator | SFXFlatHashMap::ValueIterator | SFXFlatHashMap::KeyEnumerator | SFXFlatHashMap::KeyIterator
[ public ] ValueIterator GetValueIterator(Void);
Value iterator of this hashmap.
This function gets the value iterator of this hashmap.
SFXFlatHashMap::GetValueEnumerator | SFXFlatHashMap::GetKeyIterator | SFXFlatHashMap::GetKeyEnumerator | SFXFlatHashMap::ValueEnumerator | SFXFlatHashMap::ValueIterator | SFXFlatHashMap::KeyEnumerator | SFXFlatHashMap::KeyIterator
[ public, const ] Bool IsEmpty(Void);
This function checks whether or not this hashmap is empty.
[ public ] SFCError Merge( SFXFlatHashMap< K, V > const & collection // hashmap to merge );
This function merges this hashmap with the specified this hashmap.
* In case an error occurs during processing, this hashmap will be restored.
[ public ] Void Remove( KeyType key // key to remove );
This function removes the key-value pair with the specified key from this hashmap.
If the key is of the SFXAnsiString / SFXWideString type, the string as the key will be released automatically.
Caution | |
---|---|
If the key or the value is a pointer to a class instance or data bigger than 4 bytes, data the pointer points to will not be released automatically. These data need to be released explicitly using the delete statement. Otherwise, memory leakage will occur. |
[ public ] SFCError Set( SFXFlatHashMap< K, V > const & collection // hashmap to set );
[ public ] SFCError Set( KeyType key // key to set ValueType value // value to set );
This function sets the specified key-value pair or hashmap into this hashmap.
* In case an error occurs during processing, this hashmap will be restored.
Null string | |
---|---|
The null string is the return value of the SFXAnsiString::EmptyInstance / SFXWideString::EmptyInstance function. |
SFXFlatHashMap<SFXAnsiString, SInt32> strmap; // set a key-value pair element of (key: "mike", value: 2) into the hashmap if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a key-value pair element of (key: "john", value: 1) into the hashmap if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // check whether or not this hashmap contains the key-value pair with the specified key TRACE("ContainsKey(\"mike\") = %s", (strmap.ContainsKey("mike")) ? ("true") : ("false")); // containsKey("mike") = true TRACE("ContainsKey(\"tom\") = %s", (strmap.ContainsKey("tom")) ? ("true") : ("false")); // containsKey("tom") = false } }
SFXFlatHashMap::Get | SFXFlatHashMap::operator[] | SFXAnsiString::EmptyInstance | SFXWideString::EmptyInstance
[ public ] SFCError Swap( KeyType destination // destination key KeyType source // source key );
This function swaps the value of two pair elements with the specified keys.
SFXFlatHashMap<SFXAnsiString, SInt32> strmap; // set a key-value pair element of (key: "mike", value: 2) into the hashmap if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a key-value pair element of (key: "john", value: 1) into the hashmap if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // swap the values of two pair elements if (strmap.Swap("mike", "john") == SFERR_NO_ERROR) { // display the value of the pair element with "mike" as the key on BREW Output Window TRACE("%d", strmap.Get("mike")); // 1 } } }
[ public, const ] ValueType operator[]( KeyType key // index of the element to get );
If there is the key-value pair with the specified key index in this hashmap, the corresponding value will be returned.
Otherwise, null or 0 will be returned.
This operator gets the value of the key-value pair with the specified key from this hashmap.
Caution | |
---|---|
In case no key-value pair with the specified key exists, no error will occur but this operator will return 0 or null. |
enum DefaultEnum { DEFAULT_THRESHOLD = 45 // default value of threshold to expand the hash table };
[ public ] SFMTYPEDEFCLASS(KeyEnumerator) class KeyEnumerator { public: explicit KeyEnumerator (Void); KeyEnumerator (KeyIteratorConstRef iterator); KeyEnumeratorRef operator= (KeyIteratorConstRef iterator); KeyType GetNext (Void); KeyType GetPrevious (Void); ValueType GetValue (Void) const; Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; };
This class is for managing the key enumerator for the keys of the pair elements of this hashmap.
This class has the following member functions.
GetNext | Get the next element. If no next element exists, null or 0 will be returned. |
GetPrevious | Get the previous element. If no previous element exists, null or 0 will be returned. |
HasNext | Check whether or not the next element exists. |
HasPrevious | Check whether or not the previous element exists. |
IsValid | Check whether or not the enumerator is valid. |
SFXFlatHashMap::KeyIterator | SFXFlatHashMap::ValueEnumerator | SFXFlatHashMap::ValueIterator | SFXFlatHashMap::GetKeyEnumerator | SFXFlatHashMap::GetKeyIterator | SFXFlatHashMap::GetValueEnumerator | SFXFlatHashMap::GetValueIterator
[ public ] SFMTYPEDEFCLASS(KeyIterator) class KeyIterator { public: explicit KeyIterator (Void); SFCError SetValue (ValueType type); KeyType GetNext (Void); KeyType GetPrevious (Void); ValueType GetValue (Void) const; Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; };
This class is for managing the key iterator for the keys of the pair elements of this hashmap.
This class has the following member functions.
SetValue | Set a value to the value element of current iterator. |
GetNext | Get the next element. If no next element exists, null or 0 will be returned. |
GetPrevious | Get the previous element. If no previous element exists, null or 0 will be returned. |
GetValue | Get the value element of current iterator. If invalid, return null. |
HasNext | Check whether or not the next element exists. |
HasPrevious | Check whether or not the previous element exists. |
IsValid | Check whether or not the iterator is valid. |
SFXFlatHashMap::KeyEnumerator | SFXFlatHashMap::ValueEnumerator | SFXFlatHashMap::ValueIterator | SFXFlatHashMap::GetKeyEnumerator | SFXFlatHashMap::GetKeyIterator | SFXFlatHashMap::GetValueEnumerator | SFXFlatHashMap::GetValueIterator
[ public ] SFMTYPEDEFCLASS(ValueEnumerator) class ValueEnumerator { public: explicit ValueEnumerator (Void); ValueEnumerator (ValueIteratorConstRef iterator); ValueEnumeratorRef operator= (ValueIteratorConstRef iterator); ValueType GetNext (Void); ValueType GetPrevious (Void); KeyType GetKey (Void) const; Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; };
This class is for managing the value enumerator for the values of the pair elements of this hashmap.
This class has the following member functions.
GetNext | Get the next element. If no next element exists, null or 0 will be returned. |
GetPrevious | Get the previous element. If no previous element exists, null or 0 will be returned. |
HasNext | Check whether or not the next element exists. |
HasPrevious | Check whether or not the previous element exists. |
IsValid | Check whether or not the enumerator is valid. |
SFXFlatHashMap::ValueIterator | SFXFlatHashMap::KeyEnumerator | SFXFlatHashMap::KeyIterator | SFXFlatHashMap::GetKeyEnumerator | SFXFlatHashMap::GetKeyIterator | SFXFlatHashMap::GetValueEnumerator | SFXFlatHashMap::GetValueIterator
[ public ] SFMTYPEDEFCLASS(ValueIterator) class ValueIterator { public: explicit ValueIterator (Void); SFCError Set (ValueType value); ValueType GetNext (Void); ValueType GetPrevious (Void); KeyType GetKey (Void) const; Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; };
This class is for managing the value iterator for the values of the pair elements of this hashmap.
This class has the following member functions.
Set | Set a value to the value element of current iterator. |
GetNext | Get the next element. If no next element exists, null or 0 will be returned. |
GetPrevious | Get the previous element. If no previous element exists, null or 0 will be returned. |
GetKey | Get the key element of current iterator. If invalid, return null. |
HasNext | Check whether or not the next element exists. |
HasPrevious | Check whether or not the previous element exists. |
IsValid | Check whether or not the iterator is valid. |
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |