PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXHashmap
Class that represents a map utilizing a hash table to achieve high performance in search.
#include <SFXHashmap.h.hpp>
class SFXHashmap;
SFMTYPEDEFCLASS(SFXHashmap)

Inheritance diagram

 Inheritance diagram of SFXHashmapClass

Collaboration diagram

 Collaboration diagram of SFXHashmapClass

Description

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

Member

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.

SFXHashmap::SFXHashmap
Constructor of SFXHashmap class.
[ public, explicit ]
SFXHashmap(Void);
[ public, explicit ]
SFXHashmap(
    UInt16 threshold   // threshold value that expands the hash table
    UInt16 ratio       // ration of hash table expansion
);

SFXHashmap::Clear
Clear the hashmap.
[ public ]
Void Clear(Void);

Description

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.

Example

SFXHashmap<SFXAnsiString, SInt32> strmap;
 
...

strmap.Clear();   // release all the data and memory for management

Reference

SFXHashmap::Remove


SFXHashmap::ContainsKey
Check whether the specified key element is contained or not.
[ public, const ]
Bool ContainsKey(
    KeyType key   // key to check
);

Return value

  • If contained : true
  • If not contained : false

Example

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
    }
}

Reference

SFXHashmap::ContainsValue


SFXHashmap::ContainsValue
Check whether the specified value element is contained or not.
[ public, const ]
Bool ContainsValue(
    ValueType value   // value to check
);

Return value

  • If contained : true
  • If not contained : false

Example

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
    }
}

Reference

SFXHashmap::ContainsKey


SFXHashmap::EmptyInstance
Get an empty hashmap.
[ public, static ]
SFXHashmap< K, V > const & EmptyInstance(Void);

Description

Get an instance that represents an empty hashmap.


SFXHashmap::Equals
Check whether to equal the specified hashmap or not.
[ public, const ]
Bool Equals(
    SFXHashmap< K, V > const & collection   // hashmap to compare with
);

Return value

  • If equal : true
  • If not equal : false

Description

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.


SFXHashmap::Get
Get the value element to match with the specified key.
[ public, const ]
ValueType Get(
    KeyType key   // key to get the value element
);

Return value

If there is a hashmap element to match with the specified key, rerurn its value element.

If not , return null.

Example

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
    }
}

Reference

SFXHashmap::Set


SFXHashmap::GetKeyEnumerator
Get an enumerator for key elements of hashmap.
[ public, const ]
KeyEnumerator GetKeyEnumerator(Void);

Reference

SFXHashmap::GetKeyIterator | SFXHashmap::GetValueIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator


SFXHashmap::GetKeyIterator
Get an iterator for key elements of hashmap.
[ public ]
KeyIterator GetKeyIterator(Void);

Reference

SFXHashmap::GetKeyEnumerator | SFXHashmap::GetValueEnumerator | SFXHashmap::GetValueIterator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator


SFXHashmap::GetRatio
Get the expansion ratio of hash table size.
[ public, const ]
UInt16 GetRatio(Void);

Reference

SFXHashmap::SetRatio


SFXHashmap::GetSize
Get the size(the number of key elements of hashmap).
[ public, const ]
SInt32 GetSize(Void);

SFXHashmap::GetThreshold
Get the threshold to expand the hash table size.
[ public, const ]
UInt16 GetThreshold(Void);

Reference

SFXHashmap::SetThreshold


SFXHashmap::GetValueEnumerator
Get an enumerator for value elements of hashmap.
[ public, const ]
ValueEnumerator GetValueEnumerator(Void);

Reference

SFXHashmap::GetValueIterator | SFXHashmap::GetKeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator


SFXHashmap::GetValueIterator
Get an iterator for value elements of hashmap.
[ public ]
ValueIterator GetValueIterator(Void);

Reference

SFXHashmap::GetValueEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator


SFXHashmap::IsEmpty
Check whether the hashmap is empty or not.
[ public, const ]
Bool IsEmpty(Void);

Return value

  • If empty : true
  • If not empty : false

SFXHashmap::Merge
Merge a hashmap.
[ public ]
SFCError Merge(
    SFXHashmap< K, V > const & collection   // hashmap to merge
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory: SFERR_NO_MEMOERY
  • If failed : SFERR_FAILED

Description

In case an error occurs during processing, the hashmap is restored.


SFXHashmap::Remove
Remove the element with the specified key.
[ public ]
Void Remove(
    KeyType key   // key to remove
);

SFXHashmap::Set
Set a value element for the specified key. Or set a hashmap.
[ public ]
SFCError Set(
    SFXHashmap< K, V > const & collection   // hashmap to set
);
[ public ]
SFCError Set(
    KeyType key       // key to set
    ValueType value   // value to set
);

Return value

  • Success : SFERR_NO_ERROR
  • If insufficient memory : SFERR_NO_MEMOERY
  • If failed : SFERR_FAILED

Description

In case an error occurs during processing, the hashmap is restored.

Example

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
    }
}

Reference

SFXHashmap::Get


SFXHashmap::SetRatio
Set the expansion ratio of hash table size.
[ public ]
Void SetRatio(
    UInt16 ratio   // expansion ratio to set (%)
);

Description

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.

Reference

SFXHashmap::GetRatio


SFXHashmap::SetThreshold
Set the threshold to expand the hash table size.
[ public ]
Void SetThreshold(
    UInt16 threshold   // threshold ratio to set (%)
);

Description

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)

Reference

SFXHashmap::GetThreshold


SFXHashmap::operator[]
Get the element by index.
[ public, const ]
ValueType operator[](
    KeyType key   // index of element to get
);

Return value

If there is a hashmap element to match with the specified key, rerurn its value element.

If not , return null.

Reference

SFXHashmap::Set


SFXHashmap::DefaultEnum
Default values of threshold and ratio to expand the hash table.
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
};

Reference

SFXHashmap::SetThreshold | SFXHashmap::GetThreshold | SFXHashmap::SetRatio | SFXHashmap::GetRatio


SFXHashmap::KeyEnumerator
Class for managing an enumerator for key elements of hashmap.
[ 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;
};

Description

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.

Reference

SFXHashmap::KeyIterator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::GetValueIterator


SFXHashmap::KeyIterator
Class for managing an iterator for key elements of hashmap.
[ 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);
};

Description

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.

Reference

SFXHashmap::KeyEnumerator | SFXHashmap::ValueEnumerator | SFXHashmap::ValueIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::GetValueIterator


SFXHashmap::ValueEnumerator
Class for managing an enumerator for value elements of hashmap.
[ 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;
};

Description

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.

Reference

SFXHashmap::ValueIterator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::GetValueIterator


SFXHashmap::ValueIterator
Class for managing an iterator for value elements of hashmap.
[ 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);
};

Description

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.

Reference

SFXHashmap::ValueEnumerator | SFXHashmap::KeyEnumerator | SFXHashmap::KeyIterator | SFXHashmap::GetKeyEnumerator | SFXHashmap::GetKeyIterator | SFXHashmap::GetValueEnumerator | SFXHashmap::GetValueIterator