KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
Kisaragi_Lib::SparseSet< Key, Value > クラステンプレート

#include <SparseSet.hpp>

公開メンバ関数

void Add (const Key &_key, const Value &_value)
 配列の追加
 
void Erase (const Key &_key)
 _key要素を削除する
 
 operator std::vector< Value > & ()
 
Value & operator[] (Key _key)
 

非公開変数類

std::unordered_map< Key, unsigned int > sparseContainer
 疎な配列、keyを引数としてvalue配列の引数を取得する
 
std::vector< Value > denseContainer
 密な配列、実際のバリューが格納される
 
std::vector< Key > indexToKey
 denseをループ処理するときにkeyがほしい時などに使うやつ
 

詳解

template<class Key, class Value>
class Kisaragi_Lib::SparseSet< Key, Value >
テンプレート引数
Key
Value

関数詳解

◆ Add()

template<class Key, class Value>
void Kisaragi_Lib::SparseSet< Key, Value >::Add ( const Key & _key,
const Value & _value )
inline

配列の追加

引数
_key配列のKey
_value配列の要素
40 {
41 // Keyが重複している場合は、返す
42 if (sparseContainer.count(_key) == 1)
43 {
44 return;
45 }
46
47 // valueの値を格納.
48 denseContainer.push_back(_value);
49
50 //格納する引数を計算
51 unsigned int index = denseContainer.size() - 1;
52
53 // 疎な配列を登録.
54 sparseContainer.emplace(_key, index);
55
56 // 反転も登録
57 indexToKey.push_back(_key);
58 }
Definition SparseSet.hpp:16
std::vector< Key > indexToKey
denseをループ処理するときにkeyがほしい時などに使うやつ
Definition SparseSet.hpp:31
std::unordered_map< Key, unsigned int > sparseContainer
疎な配列、keyを引数としてvalue配列の引数を取得する
Definition SparseSet.hpp:21
std::vector< Value > denseContainer
密な配列、実際のバリューが格納される
Definition SparseSet.hpp:26

◆ Erase()

template<class Key, class Value>
void Kisaragi_Lib::SparseSet< Key, Value >::Erase ( const Key & _key)
inline

_key要素を削除する

引数
_key削除する要素のKey
65 {
66
67 // Keyが存在しない場合返す
68 if (sparseContainer.count(_key) == 0)
69 {
70 return;
71 }
72
73
74 //引数を記憶
75 unsigned int index = sparseContainer[_key];
76 //末尾要素の引数を記憶
77 unsigned int lastIndex = denseContainer.size() - 1;
78
79 //自身が末尾の場合 or 自身のみしか格納してない場合.
80 // 末尾の場合交換せずに処理できる
81
82 //自身が末尾要素でない場合、awapを行う
83 if (index != lastIndex)
84 {
85 //最後の要素と入れ替える
87
88 //疎配列の交換
90
91 //indexToKeyの交換
93 }
94
95 //各配列の削除処理を行う.
96 {
97 //要素の削除
98 denseContainer.pop_back();
99 //疎配列の削除
100 sparseContainer.erase(_key);
101 //Keyの逆引きを削除
102 indexToKey.pop_back();
103 }
104 }

◆ operator std::vector< Value > &()

template<class Key, class Value>
Kisaragi_Lib::SparseSet< Key, Value >::operator std::vector< Value > & ( )
inline
108 {
109 return denseContainer;
110 }

◆ operator[]()

template<class Key, class Value>
Value & Kisaragi_Lib::SparseSet< Key, Value >::operator[] ( Key _key)
inline
113 {
115 }

メンバ詳解

◆ sparseContainer

template<class Key, class Value>
std::unordered_map<Key, unsigned int> Kisaragi_Lib::SparseSet< Key, Value >::sparseContainer
private

疎な配列、keyを引数としてvalue配列の引数を取得する

参照元 Add(), Erase(), operator[]().

◆ denseContainer

template<class Key, class Value>
std::vector<Value> Kisaragi_Lib::SparseSet< Key, Value >::denseContainer
private

密な配列、実際のバリューが格納される

参照元 Add(), Erase(), operator std::vector< Value > &(), operator[]().

◆ indexToKey

template<class Key, class Value>
std::vector<Key> Kisaragi_Lib::SparseSet< Key, Value >::indexToKey
private

denseをループ処理するときにkeyがほしい時などに使うやつ

参照元 Add(), Erase().


このクラス詳解は次のファイルから抽出されました: