![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |


Each key element of the SFXHashmap instance ( hashmap ) needs to be data not more than 4 bytes, the SFXAnsiString instance, or the SFXWideString instance. In order to process data more than 4 bytes ( such as UInt64 type, Double type, and so on ) or class instance as a value element of the SFXHashmap instance ( hashmap ), a pointer should be used.
// data more than 4 bytes or class instance cannot be a value element of the SFXHashmap instance ( hashmap ) // SFXHashmap<SFXAnsiString, SInt64> map64; NG // SFXHashmap<SFXAnsiString, SFXAnsiString> mapstr; NG // but a pointer to the data more than 4 bytes or class instance can be a value element of the SFXHashmap instance ( hashmap ) SFXHashmap<SFXAnsiString, SInt64Ptr> map64; // oK SFXHashmap<<SFXAnsiString, SFXAnsiStringPtr> mapstr; // oK
| Constructor/Destructor |
|---|
|
SFXHashmap( Void ) Constructor of SFXHashmap class.
|
|
SFXHashmap(
UInt16 threshold
, UInt16 ratio
) Constructor of SFXHashmap class.
|
| Public Functions | |
|---|---|
| Void |
Clear( Void ) Clear the hashmap.
|
| Bool |
ContainsKey(
KeyType key
) Check whether the specified key element is contained or not.
|
| Bool |
ContainsValue(
ValueType value
) Check whether the specified value element is contained or not.
|
| static SFXHashmap< K, V > const & |
EmptyInstance( Void ) Get an empty hashmap.
|
| Bool |
Equals(
SFXHashmap< K, V > const & collection
) Check whether to equal the specified hashmap or not.
|
| ValueType |
Get(
KeyType key
) Get the value element to match with the specified key.
|
| KeyEnumerator |
GetKeyEnumerator( Void ) Get an enumerator for key elements of hashmap.
|
| KeyIterator |
GetKeyIterator( Void ) Get an iterator for key elements of hashmap.
|
| UInt16 |
GetRatio( Void ) Get the expansion ratio of hash table size.
|
| SInt32 |
GetSize( Void ) Get the size(the number of key elements of hashmap).
|
| UInt16 |
GetThreshold( Void ) Get the threshold to expand the hash table size.
|
| ValueEnumerator |
GetValueEnumerator( Void ) Get an enumerator for value elements of hashmap.
|
| ValueIterator |
GetValueIterator( Void ) Get an iterator for value elements of hashmap.
|
| Bool |
IsEmpty( Void ) Check whether the hashmap is empty or not.
|
| SFCError |
Merge(
SFXHashmap< K, V > const & collection
) Merge a hashmap.
|
| Void |
Remove(
KeyType key
) Remove the element with the specified key.
|
| SFCError |
Set(
SFXHashmap< K, V > const & collection
) Set( KeyType key , ValueType value ) Set a value element for the specified key. Or set a hashmap.
|
| Void |
SetRatio(
UInt16 ratio
) Set the expansion ratio of hash table size.
|
| Void |
SetThreshold(
UInt16 threshold
) Set the threshold to expand the hash table size.
|
| ValueType |
operator[](
KeyType key
) Get the element by index.
|
| Types |
|---|
|
DefaultEnum Default values of threshold and ratio to expand the hash table.
|
|
KeyEnumerator Class for managing an enumerator for key elements of hashmap.
|
|
KeyIterator Class for managing an iterator for key elements of hashmap.
|
|
ValueEnumerator Class for managing an enumerator for value elements of hashmap.
|
|
ValueIterator Class for managing an iterator for value elements of hashmap.
|
[ public, explicit ] SFXHashmap(Void);
[ public, explicit ]
SFXHashmap(
UInt16 threshold // threshold value that expands the hash table
UInt16 ratio // ration of hash table expansion
);
[ public ] Void Clear(Void);
When using the string key, resource for managing its key is released automatically.
If the type of element is a pointer to a class instance, the instance is not released automatically.
SFXHashmap<SFXAnsiString, SInt32> strmap;
...
strmap.Clear(); // release all the data and memory for management
[ public, const ] Bool ContainsKey( KeyType key // key to check );
SFXHashmap<SFXAnsiString, SInt32> strmap; // set a hashmap element of key and value if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a hashmap element of key and value 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 );
SFXHashmap<SFXAnsiString, SInt32> strmap; // set a hashmap element of key and value if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a hashmap element of key and value 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 ] SFXHashmap< K, V > const & EmptyInstance(Void);
Get an instance that represents an empty hashmap.
[ public, const ] Bool Equals( SFXHashmap< K, V > const & collection // hashmap to compare with );
Check about two hashmaps whether the same element of key and its value is saved in the same order or not.
If the type of element is a pointer to a class instance, its address is compared.
[ public, const ]
ValueType Get(
KeyType key // key to get the value element
);If there is a hashmap element to match with the specified key, rerurn its value element.
If not , return null.
SFXHashmap<SFXAnsiString, SInt32> strmap; // set a hashmap element of key and value if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a hashmap element of key and value if (strmap.Set("john", 1) == SFERR_NO_ERROR) { // get the value element to match with the specified key TRACE("%d", strmap.Get("mike")); // 2 } }
[ public, const ] KeyEnumerator GetKeyEnumerator(Void);
SFXHashmap::GetKeyIterator | SFXHashmap::GetValueIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator
[ public ] KeyIterator GetKeyIterator(Void);
SFXHashmap::GetKeyEnumerator | SFXHashmap::GetValueEnumerator | SFXHashmap::GetValueIterator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator
[ public, const ] UInt16 GetRatio(Void);
[ public, const ] SInt32 GetSize(Void);
[ public, const ] UInt16 GetThreshold(Void);
[ public, const ] ValueEnumerator GetValueEnumerator(Void);
SFXHashmap::GetValueIterator | SFXHashmap::GetKeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator
[ public ] ValueIterator GetValueIterator(Void);
SFXHashmap::GetValueEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator
[ public, const ] Bool IsEmpty(Void);
[ public ] SFCError Merge( SFXHashmap< K, V > const & collection // hashmap to merge );
In case an error occurs during processing, the hashmap is restored.
[ public ] Void Remove( KeyType key // key to remove );
[ public ] SFCError Set( SFXHashmap< K, V > const & collection // hashmap to set );
[ public ] SFCError Set( KeyType key // key to set ValueType value // value to set );
In case an error occurs during processing, the hashmap is restored.
SFXHashmap<SFXAnsiString, SInt32> strmap; // set a hashmap element of key and value if (strmap.Set("mike", 2) == SFERR_NO_ERROR) { // set a hashmap element of key and value 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 } }
The hash table size is expanded for efficiency when the number of key elements increases.
The expansion ratio of hash table size is specified by percentage.
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 elements) * threshold / 100 > (hash table size)
[ public, const ]
ValueType operator[](
KeyType key // index of element to get
);If there is a hashmap element to match with the specified key, rerurn its value element.
If not , return null.
enum DefaultEnum {
DEFAULT_THRESHOLD = 10, // default value of threshold to expand the hash table
DEFAULT_RATIO = 50 // default value of ratio to expand the hash table
};
SFXHashmap::SetThreshold | SFXHashmap::GetThreshold | SFXHashmap::SetRatio | SFXHashmap::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;
};
The KeyEnumerator class is a class that manages an enumerator for key elements of hashmap.
The KeyEnumerator class has the following member functions.
| GetNext | Get the next element. If no next element, return null. |
| GetPrevious | Get the previous element. If no previous element, return null. |
| HasNext | Check whether the next element exists or not. |
| HasPrevious | Check whether the previous element exists or not. |
| IsValid | Check whether the enumerator is valid or not. |
SFXHashmap::KeyIterator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::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);
};
The KeyIterator class is a class that manages an iterator for key elements of hashmap.
The KeyIterator class has the following member functions.
| GetNext | Get the next element. If no next element, return null. |
| GetPrevious | Get the previous element. If no previous element, return null. |
| GetValue | Get the value element of current iterator. If invalid, return null. |
| HasNext | Check whether the next element exists or not. |
| HasPrevious | Check whether the previous element exists or not. |
| IsValid | Check whether the iterator is valid or not. |
| Remove | Remove the element of current iterator. |
SFXHashmap::KeyEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::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;
};
The ValueEnumerator class is a class that manages an enumerator for value elements of hashmap.
The ValueEnumerator class has the following member functions.
| GetNext | Get the next element. If no next element, return null. |
| GetPrevious | Get the previous element. If no previous element, return null. |
| HasNext | Check whether the next element exists or not. |
| HasPrevious | Check whether the previous element exists or not. |
| IsValid | Check whether the enumerator is valid or not. |
SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::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);
};
The ValueIterator class is a class that manages an iterator for value elements of hashmap.
The ValueIterator 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, return null. |
| GetPrevious | Get the previous element. If no previous element, return null. |
| GetKey | Get the key element of current iterator. If invalid, return null. |
| HasNext | Check whether the next element exists or not. |
| HasPrevious | Check whether the previous element exists or not. |
| IsValid | Check whether the iterator is valid or not. |
| Remove | Remove the element of current iterator. |
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|