This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Unigine::Hash class

Header: #include <UnigineHash.h>

A Hash is a collection of unique keys and their values, much like a dictionary. Hashes are also referred to as associative arrays; they are similar to arrays, but while an array uses integers as an index, a Hash can use any type of object.

Let's check some examples of class functions usage:

  • You can get the hash size and check whether the hash contains a specific key:
    Source code (C++)
    // create an empty hash set
    HashSet<String> set;
    // create two equal strings
    const char *initial_str = "aaa";
    const String aaa0(initial_str), aaa1(initial_str);
    
    // add one of the strings as a key to the hash set
    set.insert(aaa0);
    // check the result
    if (set.contains(initial_str)) Log::message("The hash set contains the recently added key\n");
    Log::message("The size is %d\n", set.size());
    
    // add the duplicate string as a key to the hash set 
    set.insert(aaa1);
    // check the result - the size of the hash set remains the same
    Log::message("The size is %d\n", set.size());
  • You can get the iterator pointing to the first key in the hash. Also, you can remove some specific key from the hash if you know its iterator.
    Source code (C++)
    // create a hash set
    HashSet<String> set0{ "1", "2", "3" };
    // copy one hash set to another
    HashSet<String> set1(set0);
    
    // remove the first key from the first hash set
    set0.erase(set0.begin());
    
    // check the result
    if (set0 != set1)
    {
    	for (const auto &i : set0) Log::message("%s ", i.key.get());
    	Log::message("\n");
    	for (const auto &j : set1) Log::message("%s ", j.key.get());
    }
  • To clear the hash set, you should use the clear() function:
    Source code (C++)
    // create a hash set
    HashSet<String> set{ "1", "2", "3", "4", "5" };
    
    // remove all keys from the hash set
    set.clear();
    // check if the set is empty
    if (set.empty()) Log::message("The set is empty\n");

Hash Class

Members


bool is_need_realloc ( ) #

Indicates whether reallocation is needed.

Return value

true if reallocation is needed, otherwise false.

void shrink ( ) #

Reduces memory usage by removing unused capacity.

Data * do_append ( const Key & key ) #

Appends an element with the specified key to the hash.

Arguments

  • const Key & key - Key of an element to be appended.

Return value

Pointer to Data.

void rehash ( Counter new_capacity ) #

Rebuilds the hash based on a specified capacity.

Arguments

  • Counter new_capacity - New hash capacity value.

Iterator begin ( ) #

Returns an iterator that points to the first element in the hash.

Return value

Iterator pointing to the first element.

ConstIterator end ( ) #

Returns a const iterator that points to the location succeeding the last element in the hash.

Return value

Const iterator pointing to the location after the last element.

Vector<Key> keys ( ) #

Returns a vector containing all the keys in the hash.

Return value

Vector of keys.

bool remove ( const ConstIterator & it ) #

Removes an element currently pointed to by the iterator from the hash.

Arguments

  • const ConstIterator & it - Iterator pointing to an element to be removed.

Return value

true on success, otherwise false.

Counter space ( ) #

Returns current capacity (number of elements the hash can currently contain).

Return value

Number of elements the hash can currently contain.

Data * do_append ( Key && key ) #

Appends an element with the specified key to the hash.

Arguments

  • Key && key - Key of an element to be appended.

Return value

Pointer to Data.

bool erase ( const ConstIterator & it ) #

Removes an element currently pointed to by the iterator from the hash.

Arguments

  • const ConstIterator & it - Iterator pointing to the element to be removed.

Return value

true on success, otherwise false.

bool erase ( const Iterator & it ) #

Removes an element currently pointed to by the iterator from the hash.

Arguments

  • const Iterator & it - Iterator pointing to the element to be removed.

Return value

true on success, otherwise false.

Counter round_up ( Counter v ) #

Performs rounding and returns the result.

Arguments

  • Counter v

void swap ( Hash<Key, Data, HashType, Counter> & hash ) #

Swaps this hash with the specified one.

Arguments

  • Hash<Key, Data, HashType, Counter> & hash - Specified hash.

Data * do_append ( HashType hash, const Key & key ) #

Appends an element with the specified key to the specified hash.

Arguments

  • HashType hash - Specified hash.
  • const Key & key - Key of an element to be appended.

Return value

Pointer to Data.

void rehash_data ( Counter index ) #

Rebuilds the hash.

Arguments

  • Counter index

Counter empty ( ) #

Checks if the hash is empty or not.

Return value

1 if the hash is empty, otherwise 0

bool contains ( const Key & key ) #

Checks if the given key is present in the hash.

Arguments

  • const Key & key - Key to be looked for.

Return value

true if the given key is present in the hash, otherwise false.

void clear ( ) #

Removes all key-value pairs from the hash.

bool do_remove ( HashType hash, const Key & key ) #

Removes an element with the specified key from the specified hash.

Arguments

  • HashType hash - Specified hash.
  • const Key & key - Key of an element to be removed.

Return value

true on success, otherwise false.

void getKeys ( Vector<Key> & keys ) #

Adds keys of the hash to the specified vector.

Arguments

  • Vector<Key> & keys - Specified vector to store the keys in.

void reserve ( Counter size ) #

Reserves storage to avoid repeated reallocation.

Arguments

  • Counter size - Hash size to be reserved.

bool erase ( const Key & key ) #

Removes an element having the specified key from the hash.

Arguments

  • const Key & key - Key of an element to be removed.

Return value

true on success, otherwise false.

Data ** do_find ( const Key & key ) #

Finds an element with a specified key.

Arguments

  • const Key & key - Key to look for.

Return value

Data of the element with the specified key if it exists, otherwise nullptr.

void realloc ( ) #

Performs memory reallocation.

bool remove ( const Key & key ) #

Removes an element having the specified key from the hash.

Arguments

  • const Key & key - Key of an element to be removed.

bool remove ( const Iterator & it ) #

Removes an element currently pointed to by the iterator from the hash.

Arguments

  • const Iterator & it - Iterator pointing to the element to be removed.

Return value

true on success, otherwise false.

void destroy ( ) #

Deletes the hash.

Counter size ( ) #

Returns the number of key-value pairs in the hash.

Return value

Number of key-value pairs in the hash.

Iterator end ( ) #

Returns an iterator that points to the location succeeding the last element in the hash.

Return value

Iterator pointing to the location after the last element.

ConstIterator begin ( ) #

Returns a const iterator that points to the first element in the hash.

Return value

Iterator pointing to the first element.

ConstIterator find ( const Key & key ) #

Finds an element with a specified key.

Arguments

  • const Key & key - Key to look for.

Return value

Iterator pointing to the element with a specified key if it exists, or to the end of the hash if it does not.

Iterator find ( const Key & key ) #

Finds an element with a specified key.

Arguments

  • const Key & key - Key to look for.

Return value

Iterator pointing to the element with a specified key if it exists, or to the end of the hash if it does not.
Last update: 2024-12-13
Build: ()