MCPcopy Create free account
hub / github.com/aiekick/ImGuiFileDialog / SearchableVector

Class SearchableVector

ImGuiFileDialog.h:255–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253
254template <typename T>
255class SearchableVector {
256private:
257 std::unordered_map<T, size_t> m_Dico;
258 std::vector<T> m_Array;
259
260public:
261 void clear() {
262 m_Dico.clear();
263 m_Array.clear();
264 }
265 bool empty() const {
266 return m_Array.empty();
267 }
268 size_t size() const {
269 return m_Array.size();
270 }
271 T& operator[](const size_t& vIdx) {
272 return m_Array[vIdx];
273 }
274 T& at(const size_t& vIdx) {
275 return m_Array.at(vIdx);
276 }
277 typename std::vector<T>::iterator begin() {
278 return m_Array.begin();
279 }
280 typename std::vector<T>::const_iterator begin() const {
281 return m_Array.begin();
282 }
283 typename std::vector<T>::iterator end() {
284 return m_Array.end();
285 }
286 typename std::vector<T>::const_iterator end() const {
287 return m_Array.end();
288 }
289
290 bool try_add(T vKey) {
291 if (!exist(vKey)) {
292 m_Dico[vKey] = m_Array.size();
293 m_Array.push_back(vKey);
294 return true;
295 }
296 return false;
297 }
298
299 bool try_set_existing(T vKey) {
300 if (exist(vKey)) {
301 auto row = m_Dico.at(vKey);
302 m_Array[row] = vKey;
303 return true;
304 }
305 return false;
306 }
307
308 bool exist(const std::string& vKey) const {
309 return (m_Dico.find(vKey) != m_Dico.end());
310 }
311};
312

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected