SophiaFramework UNIVERSE 5.3 |
DEPRECATED | |
---|---|
It is recommended not to use this class since it will be deprecated in SophiaFramework UNIVERSE 6.0. Instead, use the SFXLinkedHashMap class. |
Each key element of the SFXOldHashmap 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 class instance as a value element of the SFXOldHashmap instance(hashmap), a pointer should be used.
// data more than 4 byte or class instance cannot be a value element of the SFXOldHashmap instance ( hashmap ) // SFXOldHashmap<SFXAnsiString, SInt64> map64; NG // SFXOldHashmap<SFXAnsiString, SFXAnsiString> mapstr; NG // but a pointer to the data more than 4 byte or class instance can be a value element of the SFXOldHashmap instance ( hashmap ) SFXOldHashmap<SFXAnsiString, SInt64Ptr> map64; // OK SFXOldHashmap<<SFXAnsiString, SFXAnsiStringPtr> mapstr; // OK
Change of Specification | |
---|---|
The size of the hash table will automatically expand by an appropriate prime number when the number of the elements exceeds the threshold set with the SFXOldHashmap::SetThreshold function. Therefore the SFXOldHashmap::SetRatio and SFXOldHashmap::SetRatio functions are invalid. Since the SFXOldHashmap class can save multiple elements into one hashmap table entry, you can specify a number bigger than 100 as threshold value(default value is 80). Specifying threshold value bigger than 100, you can save scarce memory of mobile phone. |
Constructor/Destructor |
---|
SFXOldHashmap( Void ) Constructor of the SFXOldHashmap class.
|
SFXOldHashmap(
UInt16 threshold
, UInt16 ratio
) Constructor of the SFXOldHashmap class.
|
Public Functions | |
---|---|
Void |
Clear( Void ) Clear the 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 SFXOldHashmap< K, V > const & |
EmptyInstance( Void ) Get the empty hashmap.
|
Bool |
Equals(
SFXOldHashmap< K, V > const & collection
) Check whether or not this hashmap equals the specified hashmap.
|
ValueType |
Get(
KeyType key
) 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.
|
UInt16 |
GetRatio( Void ) [INVALID] Get the expansion ratio of the hash table size.
|
SInt32 |
GetSize( Void ) Get the size of this hashmap.
|
UInt16 |
GetThreshold( Void ) Get the threshold to expand the hash table size.
|
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(
SFXOldHashmap< 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(
SFXOldHashmap< 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.
|
Void |
SetRatio(
UInt16 ratio
) [INVALID] Set the expansion ratio of the hash table size.
|
Void |
SetThreshold(
UInt16 threshold
) Set the threshold to expand the hash table size.
|
ValueType |
operator[](
KeyType key
) Get the value of the key-value pair with the specified key index from this hashmap.
|
Types |
---|
DefaultEnum Default values of threshold and ratio 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 ] SFXOldHashmap(Void);
[ public, explicit ] SFXOldHashmap( UInt16 threshold // threshold value that expands the hash table UInt16 ratio // expansion ration of the hash table );
[ 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. |
SFXOldHashmap<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. |
SFXOldHashmap<SFXAnsiString, SInt32> strmap; // set a key-value pair element of (key: "mike", value: 2) into hashmap if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a key-value pair element of (key: "john", value: 1) into hashmap if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // check whether the key element is contained or not 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. |
SFXOldHashmap<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 the value element is contained or not 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 ] SFXOldHashmap< K, V > const & EmptyInstance(Void);
Empty hashmap
This function gets the empty hashmap.
[ public, const ] Bool Equals( SFXOldHashmap< 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 );
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.
Caution | |
---|---|
In case no key-value pair with the specified key exists, no error will occur but this function will return 0 or null. |
SFXOldHashmap<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) { // get the value element to match the specified key 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.
SFXOldHashmap::GetKeyIterator | SFXOldHashmap::GetValueIterator | SFXOldHashmap::GetValueEnumerator | SFXOldHashmap::ValueEnumerator | SFXOldHashmap::ValueIterator | SFXOldHashmap::KeyEnumerator | SFXOldHashmap::KeyIterator
[ public ] KeyIterator GetKeyIterator(Void);
Key iterator of this hashmap.
This function gets the key iterator of this hashmap.
SFXOldHashmap::GetKeyEnumerator | SFXOldHashmap::GetValueEnumerator | SFXOldHashmap::GetValueIterator | SFXOldHashmap::ValueEnumerator | SFXOldHashmap::ValueIterator | SFXOldHashmap::KeyEnumerator | SFXOldHashmap::KeyIterator
[ public, const ] UInt16 GetRatio(Void);
[ 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 ] UInt16 GetThreshold(Void);
[ public, const ] ValueEnumerator GetValueEnumerator(Void);
Value enumerator of this hashmap.
This function gets the value enumerator of this hashmap.
SFXOldHashmap::GetValueIterator | SFXOldHashmap::GetKeyIterator | SFXOldHashmap::GetKeyEnumerator | SFXOldHashmap::ValueEnumerator | SFXOldHashmap::ValueIterator | SFXOldHashmap::KeyEnumerator | SFXOldHashmap::KeyIterator
[ public ] ValueIterator GetValueIterator(Void);
Value iterator of this hashmap.
This function gets the value iterator of this hashmap.
SFXOldHashmap::GetValueEnumerator | SFXOldHashmap::GetKeyIterator | SFXOldHashmap::GetKeyEnumerator | SFXOldHashmap::ValueEnumerator | SFXOldHashmap::ValueIterator | SFXOldHashmap::KeyEnumerator | SFXOldHashmap::KeyIterator
[ public, const ] Bool IsEmpty(Void);
This function checks whether or not this hashmap is empty.
[ public ] SFCError Merge( SFXOldHashmap< 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( SFXOldHashmap< 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. |
SFXOldHashmap<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 the key element is contained or not TRACE("ContainsKey(\"mike\") = %s", (strmap.ContainsKey("mike")) ? ("true") : ("false")); // containsKey("mike") = true TRACE("ContainsKey(\"tom\") = %s", (strmap.ContainsKey("tom")) ? ("true") : ("false")); // containsKey("tom") = false } }
SFXOldHashmap::Get | SFXOldHashmap::operator[] | SFXAnsiString::EmptyInstance | SFXWideString::EmptyInstance
The specification of this function is changed. The size of the hash table will automatically expand by an appropriate prime number when the number of the elements exceeds the threshold set with the SFXOldHashmap::SetThreshold function.
The hash table size is expanded for efficiency when the number of key elements increases.
The hash table size is automatically expanded when the following condition is satisfied.
(the number of the elements) > (hash table size) * threshold / 100
Default: 80
Value of Threshold | |
---|---|
Since one table entry has multiple elements in SFXOldHashmap when the keys of the hash table collide, SFXOldHashmap can hold more elements than the hash table size. Therefore the threshold set with the SFXOldHashmap::SetThreshold function may be bigger than 100. |
[ 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 = 80, // default value of threshold to expand the hash table DEFAULT_RATIO = 50 // default value of ratio to expand the hash table };
SFXOldHashmap::SetThreshold | SFXOldHashmap::GetThreshold | SFXOldHashmap::SetRatio | SFXOldHashmap::GetRatio
[ 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. |
SFXOldHashmap::KeyIterator | SFXOldHashmap::ValueEnumerator | SFXOldHashmap::ValueIterator | SFXOldHashmap::GetKeyEnumerator | SFXOldHashmap::GetKeyIterator | SFXOldHashmap::GetValueEnumerator | SFXOldHashmap::GetValueIterator
[ public ] SFMTYPEDEFCLASS(KeyIterator) class KeyIterator { public: explicit KeyIterator (Void); KeyType GetNext (Void); KeyType GetPrevious (Void); ValueType GetValue (Void) const; Bool HasNext (Void) const; Bool HasPrevious (Void) const; Bool IsValid (Void) const; Void Remove (Void); };
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.
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. |
Remove | Remove the element of current iterator. |
SFXOldHashmap::KeyEnumerator | SFXOldHashmap::ValueEnumerator | SFXOldHashmap::ValueIterator | SFXOldHashmap::GetKeyEnumerator | SFXOldHashmap::GetKeyIterator | SFXOldHashmap::GetValueEnumerator | SFXOldHashmap::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. |
SFXOldHashmap::ValueIterator | SFXOldHashmap::KeyEnumerator | SFXOldHashmap::KeyIterator | SFXOldHashmap::GetKeyEnumerator | SFXOldHashmap::GetKeyIterator | SFXOldHashmap::GetValueEnumerator | SFXOldHashmap::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; Void Remove (Void); };
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. |
Remove | Remove the element of current iterator. |
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |