This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
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
创建内容
内容优化
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

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.

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 &k : hashSet)
    	Log::message("%d ", k.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> expected(initial);
    // check the result
    for (const auto &k : expected)
    	Log::message("%s ", k.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 &k : hashSet)
    	Log::message("%s ", k.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 &k : initial)
    	Log::message("%s ", k.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 &k : set)
    	Log::message("%s ", k.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 of the Hash class:
    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 copying 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.

HashSet<Key, Counter> & operator= ( const HashSet& o ) #

Assignment operator for the hash set.

Arguments

  • const HashSet& o - Hash set.

HashSet<Key, Counter> & operator= ( HashSet&& o ) #

Assignment operator for the hash set.

Arguments

  • HashSet&& o - Hash set.

void append ( const Key& key ) #

Appends a key to the hash set.

Arguments

  • const Key& key - Key.

void append ( Key&& key ) #

Appends a key to the hash set.

Arguments

  • Key&& key - Key.

void append ( const HashSet& o ) #

Appends a given hash set to the current one.

Arguments

  • const HashSet& o - Hash set.

void append ( HashSet&& o ) #

Appends a given hash set to the current one.

Arguments

  • HashSet&& o - Hash set.

void remove ( const HashSet& o ) #

Removes all keys of a given hash set from the current one.

Arguments

  • const HashSet& o - Hash set.

void insert ( const Key& key ) #

Inserts a key into the hash set.

Arguments

  • const Key& key - Key.

void insert ( Key&& key ) #

Inserts a key into the hash set.

Arguments

  • Key&& key - Key.

void insert ( const HashSet& o ) #

Inserts a given hash set into the current one.

Arguments

  • const HashSet& o - Hash set.

void insert ( HashSet&& o ) #

Inserts a given hash set into the current one.

Arguments

  • HashSet&& o - Hash set.

void subtract ( const HashSet& o ) #

Removes all keys of a given hash set from the current one.

Arguments

  • const HashSet& o - Hash set.

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

Checks if two hash sets are equal. The hash sets are considered equal if their keys are the same.

Arguments

  • const HashSet& o - Hash set.

Return value

Returns 1 if sets are equal; otherwise, 0 is returned.

bool operator!= ( const HashSet& o ) const#

Checks if two hash sets are not equal. The hash sets are considered equal if their keys are the same.

Arguments

  • const HashSet& o - Hash set.

Return value

Returns 1 if sets are not equal; otherwise, 0 is returned.

HashSet<Key, Counter> & operator+= ( const Key& key ) #

Inserts a given key into the hash set and returns the updated set.

Arguments

  • const Key& key - Key.

Return value

Updated hash set.

HashSet<Key, Counter> & operator+= ( const HashSet& o ) #

Inserts a given hash set into the current one and returns the updated set.

Arguments

  • const HashSet& o - Hash set.

Return value

Updated hash set.

HashSet<Key, Counter> & operator-= ( const Key& key ) #

Removes a given key from the current hash set and returns the updated set.

Arguments

  • const Key& key - Key.

Return value

Updated hash set.

HashSet<Key, Counter> & operator-= ( const HashSet& o ) #

Removes a given hash set from the current one and returns the updated set.

Arguments

  • const HashSet& o - Hash set.

Return value

Updated hash set.

HashSet<Key, Counter> fromKeys ( const Key* keys, size_t size ) #

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

Arguments

  • const Key* keys - Keys pointer.
  • size_t size - Keys size.

Return value

Updated hash set.

HashSet<Key, Counter> 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.

HashSet<Key, Counter> 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.
Last update: 2022-12-14
Build: ()