diff options
Diffstat (limited to 'core/vmap.h')
-rw-r--r-- | core/vmap.h | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/core/vmap.h b/core/vmap.h index 84ae1aaf66..c91ea9b3c9 100644 --- a/core/vmap.h +++ b/core/vmap.h @@ -38,14 +38,12 @@ template <class T, class V> class VMap { public: struct Pair { - T key; V value; _FORCE_INLINE_ Pair() {} _FORCE_INLINE_ Pair(const T &p_key, const V &p_value) { - key = p_key; value = p_value; } @@ -55,10 +53,10 @@ private: CowData<Pair> _cowdata; _FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const { - r_exact = false; - if (_cowdata.empty()) + if (_cowdata.empty()) { return 0; + } int low = 0; int high = _cowdata.size() - 1; @@ -66,8 +64,9 @@ private: int middle = 0; #ifdef DEBUG_ENABLED - if (low > high) + if (low > high) { ERR_PRINT("low > high, this may be a bug"); + } #endif while (low <= high) { middle = (low + high) / 2; @@ -83,15 +82,16 @@ private: } //return the position where this would be inserted - if (a[middle].key < p_val) + if (a[middle].key < p_val) { middle++; + } return middle; } _FORCE_INLINE_ int _find_exact(const T &p_val) const { - - if (_cowdata.empty()) + if (_cowdata.empty()) { return -1; + } int low = 0; int high = _cowdata.size() - 1; @@ -115,7 +115,6 @@ private: public: int insert(const T &p_key, const V &p_val) { - bool exact; int pos = _find(p_key, exact); if (exact) { @@ -127,25 +126,22 @@ public: } bool has(const T &p_val) const { - return _find_exact(p_val) != -1; } void erase(const T &p_val) { - int pos = _find_exact(p_val); - if (pos < 0) + if (pos < 0) { return; + } _cowdata.remove(pos); } int find(const T &p_val) const { - return _find_exact(p_val); } int find_nearest(const T &p_val) const { - bool exact; return _find(p_val, exact); } @@ -154,37 +150,30 @@ public: _FORCE_INLINE_ bool empty() const { return _cowdata.empty(); } const Pair *get_array() const { - return _cowdata.ptr(); } Pair *get_array() { - return _cowdata.ptrw(); } const V &getv(int p_index) const { - return _cowdata.get(p_index).value; } V &getv(int p_index) { - return _cowdata.get_m(p_index).value; } const T &getk(int p_index) const { - return _cowdata.get(p_index).key; } T &getk(int p_index) { - return _cowdata.get_m(p_index).key; } inline const V &operator[](const T &p_key) const { - int pos = _find_exact(p_key); CRASH_COND(pos < 0); @@ -193,7 +182,6 @@ public: } inline V &operator[](const T &p_key) { - int pos = _find_exact(p_key); if (pos < 0) { pos = insert(p_key, V()); @@ -202,11 +190,13 @@ public: return _cowdata.get_m(pos).value; } - _FORCE_INLINE_ VMap(){}; + _FORCE_INLINE_ VMap() {} _FORCE_INLINE_ VMap(const VMap &p_from) { _cowdata._ref(p_from._cowdata); } + inline VMap &operator=(const VMap &p_from) { _cowdata._ref(p_from._cowdata); return *this; } }; + #endif // VMAP_H |