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
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::HashSet Class

Header: #include <UnigineHashSet.h>

A hash set container template. The hash set stores keys in an unspecified order. It allows for fast lookup of the keys. For example, you can implement fast searching among nodes by their IDs.

Data are stored in the memory linearly, i.e. as a vector:

Notice
Key and Value address may change throughout the hashmap existense. This way of storing hash set data is more performance-friendly, but if you need the hash set address to remain unchanged, use BucketHashSet class.

To create a new hash set, you can use the default constructor or one of the following ways:

  • Create a hash set using an initializer list:
    Source code (C++)
    // constructor that takes an initializer list
    const HashSet<int> hashSet{ 4,7,2 };
    // check the result
    for (const auto &it : hashSet)
    	Log::message("%d ", it.key);
  • Create a hash set using a copy constructor:
    Source code (C++)
    // constructor that takes an initializer list
    const HashSet<String> initial{ "a", "e" };
    // copy constructor
    const HashSet<String> copied(initial);
    // check the result
    for (const auto &it : copied)
    	Log::message("%s ", it.key.get());
  • Create a new hash set by appending a vector of keys to it by using the fromKeys() function:
    Source code (C++)
    // create a vector of keys
    Vector<String> keys{ "1", "2", "3" };
    // append keys to an empty hash set
    HashSet<String> hashSet = HashSet<String>::fromKeys(keys);
    // check the result
    for (const auto &it : hashSet)
    	Log::message("%s ", it.key.get());

You can change the created hash set by using the class member functions described in the article. Check some of the usage examples:

  • To add keys to the current hash set, you can use one of the append() or insert() functions:
    Source code (C++)
    // create hash sets using initializer lists
    HashSet<String> initial{ "a", "b", "c", "d", "e" };
    HashSet<String> to_add{ "m", "n", "o" };
    
    // append keys of the "to_add" hash set to the "initial" hash set
    initial.append(to_add);
    // insert a key into the "initial" hash set
    initial.insert("s");
    // check the result
    for (const auto &it : initial)
    	Log::message("%s ", it.key.get());
    Also it is possible to insert keys by using operator+=:
    Source code (C++)
    // create hash sets using initializer lists
    HashSet<String> initial{ "a", "e" };
    const HashSet<String> to_add{ "b", "c", "d" };
    const HashSet<String> expected{ "a", "b", "c", "d", "e" };
    
    // add one hash set to another
    initial += to_add;
    // check the result
    if (initial == expected) Log::message("The hash set has been added successfully\n");
    Notice
    If the key already exists in the hash set, it won't be added.
    Source code (C++)
    // create a hash set
    HashSet<String> set{ "s" };
    // assign one hash set to another
    const HashSet<String> original = set;
    
    // insert the hash set into the same hash set
    set.insert(set);
    // check the result - the hash set remains the same
    if (set == original) Log::message("Sets are equal\n");
    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());
  • To remove keys from the hash set, you can use the subtract() or remove() function:
    Source code (C++)
    // create hash sets
    HashSet<String> initial{ "a", "b", "c", "d", "e" };
    const HashSet<String> to_subtract{ "a", "c", "e" };
    const HashSet<String> expected{ "b", "d" };
    
    // remove keys of one hash set from another
    initial.subtract(to_subtract);
    // check if the hash sets are equal
    if (initial == expected)  Log::message("Sets are equal\n");
    Source code (C++)
    // create hash sets
    HashSet<String> set{ "1", "2", "3", "4", "5" };
    HashSet<String> to_remove{ "3", "5" };
    
    // remove keys of one hash set from another
    set.remove(to_remove);
    // check the result
    for (const auto &it : set)
    	Log::message("%s ", it.key.get());
    Also the operator-= can be used:
    Source code (C++)
    // create hash sets
    HashSet<String> initial{ "a", "b", "c", "d", "e" };
    const HashSet<String> to_subtract{ "a", "c", "e" };
    const HashSet<String> expected{ "b", "d" };
    
    // remove keys of one hash set from another
    initial -= to_subtract;
    // check if the hash sets are equal
    if (initial == expected)  Log::message("Sets are equal\n");
  • To clear the hash set, 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");

HashSet Class

Members


HashSet ( ) #

Default constructor that produces an empty hash set.

HashSet ( const HashSet& o ) #

Constructor. Creates a hash set by copying a source hash set.

Arguments

  • const HashSet& o - Hash set.

HashSet ( HashSet&& o ) #

Constructor. Creates a hash set by moving a source hash set.

Arguments

  • HashSet&& o - Hash set.

HashSet ( std::initializer_list<Key> list ) #

Constructor. Creates a hash set from given list of keys.

Arguments

  • std::initializer_list<Key> list - List of keys.

void append ( const Key& key ) #

Appends a key to the hash set by copying the argument.

Arguments

  • const Key& key - Key.

void append ( Key&& key ) #

Appends a key to the hash set by moving the argument.

Arguments

  • Key&& key - Key.

void append ( const HashSet& o ) #

Appends items with all available keys from the argument hash set to the current hash set.

Arguments

  • const HashSet& o - Hash set to be appended.

void append ( HashSet&& o ) #

Appends items with all available keys by moving the argument hash set to the current hash set.

Arguments

  • HashSet&& o - Hash set to be appended.

void append ( const Vector& vector ) #

Appends items with all available keys from the argument vector to the current hash set.

Arguments

  • const Vector& vector - Vector containing the key (or keys) to be appended.

void append ( Vector&& vector ) #

Appends items with all available keys by moving the argument vector to the current hash set.

Arguments

  • Vector&& vector - Vector containing the key (or keys) to be appended.

void insert ( const Key& key ) #

Inserts a key into the hash set by copying the argument.

Arguments

  • const Key& key - Key.

void insert ( Key&& key ) #

Inserts a key into the hash set by moving the argument.

Arguments

  • Key&& key - Key.

HashSet & operator+= ( const Key& k ) #

Appends a given key to this hash set and returns this hash set.

Arguments

  • const Key& k - Key.

Return value

Updated hash set.

HashSet & operator+= ( const HashSet& o ) #

Appends a given hash set to this hash set and returns this hash set.

Arguments

  • const HashSet& o - Hash set to be added.

Return value

Updated hash set.

HashSet & operator-= ( const Key& k ) #

Removes a given key from this hash set and returns this hash set.

Arguments

  • const Key& k - Key.

Return value

Updated hash set.

HashSet & operator-= ( const HashSet& o ) #

Removes a given hash set from this hash set and returns this hash set.

Arguments

  • const HashSet& o - Hash set to be removed.

Return value

Updated hash set.

static HashSet fromKeys ( const Key* keys, size_t size ) #

Appends keys to the hash set and returns the updated set.

Arguments

  • const Key* keys - Pointer to the keys.
  • size_t size - Keys size.

Return value

Updated hash set.

static HashSet fromKeys ( const Vector<Key>& keys ) #

Appends keys to the hash set and returns the updated set.

Arguments

  • const Vector<Key>& keys - Vector of keys.

Return value

Updated hash set.

static HashSet fromKeys ( Vector<Key>& keys ) #

Appends keys to the hash set and returns the updated set.

Arguments

  • Vector<Key>& keys - Vector of keys.

Return value

Updated hash set.

void insert ( const HashSet& o ) #

Inserts items with all available keys by copying the argument hash to the current hash set.

Arguments

  • const HashSet& o - Hash set containing the key (or keys) to be inserted.

void insert ( HashSet&& o ) #

Inserts items with all available keys by moving the argument hash to the current hash set.

Arguments

  • HashSet&& o - Hash set containing the key (or keys) to be inserted.

void insert ( const Vector& vector ) #

Inserts items with all available keys by copying the argument vector to the current hash set.

Arguments

  • const Vector& vector - Vector containing the key (or keys) to be inserted.

void insert ( Vector&& vector ) #

Inserts items with all available keys by moving the argument vector to the current hash set.

Arguments

  • Vector&& vector - Vector containing the key (or keys) to be inserted.

HashSet & operator= ( const HashSet & o ) #

Assigns the specified hash set by copying it.

Arguments

  • const HashSet & o - Hash set.

Return value

Hash set.

HashSet & operator= ( HashSet&& o ) #

Assigns the specified hash set by moving it.

Arguments

  • HashSet&& o - Hash set.

Return value

Hash set.

emplaceRange ( InputIt first, InputIt last ) #

Inserts the range of values specified by the argument iterators into the hash set.

Arguments

  • InputIt first - Iterator that identifies the beginning of the range.
  • InputIt last - Iterator that identifies the end of the range.

bool contains ( const Key & k ) const#

Checks if the given key is present in the hash set.

Arguments

  • const Key & k - Key to be checked.

Return value

true if the hash set contains the specified key; otherwise, false.

Iterator find ( const Key & k ) const#

Returns the iterator of the specified key.

Arguments

  • const Key & k - Key to be checked.

Return value

Item iterator.

ConstIterator find ( const Key & k ) const#

Returns the iterator of the specified key.

Arguments

  • const Key & k - Key to be checked.

Return value

Item iterator.

Item * findFast ( const Key & key ) const#

Finds an element with a specified key.

Arguments

  • const Key & key - Key to look for.

Return value

Pointer to the hash set item.

Vector<Key> keys ( ) const#

Returns a vector containing all keys in the hash set.

Return value

Vector of keys.

void getKeys ( Vector<Key>& keys ) const#

Adds keys of the hash to the specified vector.

Arguments

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

const Key & getKey ( size_t index ) const#

Returns the key by its index.

Arguments

  • size_t index - Index number of the key in the hash set.

Return value

Key.

bool remove ( const Key& k ) #

Removes the specified key from the hash set.

Arguments

  • const Key& k - Key to be removed.

Return value

true if the key is removed successfully; otherwise, false.

void remove ( Iterator it ) #

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

Arguments

  • Iterator it - Iterator pointing to an element to be removed.

void remove ( ConstIterator it ) #

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

Arguments

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

void remove ( const HashSet& o ) #

Removes the specified hash set from the current hash set.

Arguments

  • const HashSet& o - Hash set.

void remove ( const Vector<Key>& v ) #

Removes the specified keys from the hash set.

Arguments

  • const Vector<Key>& v - Vector storing the keys.

bool erase ( const ConstIterator & it ) #

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

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 set.

Arguments

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

Return value

true on success, otherwise false.

bool erase ( const Key& k ) #

Removes an element having the specified key from the hash set.

Arguments

  • const Key& k - Key of the element to be removed.

Return value

true on success, otherwise false.

void erase ( const HashSet& o ) #

Removes the specified hash set from the current hash set.

Arguments

  • const HashSet& o - Hash set to be removed.

void erase ( const Vector<Key>& v ) #

Removes the specified keys from the hash set.

Arguments

  • const Vector<Key>& v - Vector storing the keys.

void subtract ( const Vector<Key>& vector ) #

Removes the specified keys from the hash set.

Arguments

  • const Vector<Key>& vector - Vector storing the keys.

void subtract ( const HashSet & o ) #

Removes the specified hash set from the current hash set.

Arguments

  • const HashSet & o - Hash set to be removed.

void clear ( ) #

Removes all key-value pairs from the hash set.

void destroy ( ) #

Removes all key-value pairs from the hash set and releases the memory.

void reserve ( size_t size ) #

Reserves storage to avoid repeated reallocation.

Arguments

  • size_t size - Hash size to be reserved.

void shrink ( ) #

Removes unused capacity.

Iterator begin ( ) const#

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

Return value

Iterator pointing to the first element.

Iterator end ( ) const#

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

Return value

Iterator pointing to the last element.

ConstIterator cbegin ( ) const#

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

Return value

ConstIterator pointing to the first element.

ConstIterator cend ( ) const#

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

Return value

ConstIterator pointing to the last element.

Counter size ( ) const#

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

Return value

Number of key-value pairs in the hash set.

Counter space ( ) const#

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

Return value

Number of elements the hash can currently contain.

size_t getMemoryUsage ( ) const#

Shows the amount of memory used by the hash set in bytes.

Return value

Used memory in bytes.

bool empty ( ) const#

Checks if the hash set is empty.

Return value

true if the hash set is empty, otherwise false

void swap ( HashSet & o ) #

Swaps this hash set with the hash set specified as the argument.

Arguments

  • HashSet & o - Hash set.
Last update: 2024-12-24
Build: ()