summaryrefslogtreecommitdiffstats
path: root/core/vmap.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/vmap.h
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
downloadredot-engine-5dbf1809c6e3e905b94b8764e99491e608122261.tar.gz
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'core/vmap.h')
-rw-r--r--core/vmap.h102
1 files changed, 43 insertions, 59 deletions
diff --git a/core/vmap.h b/core/vmap.h
index 3708cbed5b..8446015568 100644
--- a/core/vmap.h
+++ b/core/vmap.h
@@ -32,7 +32,7 @@
#include "typedefs.h"
#include "vector.h"
-template<class T,class V>
+template <class T, class V>
class VMap {
struct _Pair {
@@ -42,64 +42,61 @@ class VMap {
_FORCE_INLINE_ _Pair() {}
- _FORCE_INLINE_ _Pair(const T& p_key, const V& p_value) {
+ _FORCE_INLINE_ _Pair(const T &p_key, const V &p_value) {
- key=p_key;
- value=p_value;
+ key = p_key;
+ value = p_value;
}
-
};
Vector<_Pair> _data;
- _FORCE_INLINE_ int _find(const T& p_val,bool &r_exact) const {
+ _FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const {
- r_exact=false;
+ r_exact = false;
if (_data.empty())
return 0;
int low = 0;
- int high = _data.size() -1;
+ int high = _data.size() - 1;
int middle;
- const _Pair *a=&_data[0];
+ const _Pair *a = &_data[0];
- while( low <= high )
- {
- middle = ( low + high ) / 2;
+ while (low <= high) {
+ middle = (low + high) / 2;
- if( p_val < a[ middle].key ) {
+ if (p_val < a[middle].key) {
high = middle - 1; //search low end of array
- } else if ( a[middle].key < p_val) {
+ } else if (a[middle].key < p_val) {
low = middle + 1; //search high end of array
} else {
- r_exact=true;
+ r_exact = true;
return middle;
}
}
//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 {
+ _FORCE_INLINE_ int _find_exact(const T &p_val) const {
if (_data.empty())
return -1;
int low = 0;
- int high = _data.size() -1;
+ int high = _data.size() - 1;
int middle;
- const _Pair *a=&_data[0];
+ const _Pair *a = &_data[0];
- while( low <= high )
- {
- middle = ( low + high ) / 2;
+ while (low <= high) {
+ middle = (low + high) / 2;
- if( p_val < a[ middle].key ) {
+ if (p_val < a[middle].key) {
high = middle - 1; //search low end of array
- } else if ( a[middle].key < p_val) {
+ } else if (a[middle].key < p_val) {
low = middle + 1; //search high end of array
} else {
return middle;
@@ -110,49 +107,45 @@ class VMap {
}
public:
-
- int insert(const T& p_key,const V& p_val) {
+ int insert(const T &p_key, const V &p_val) {
bool exact;
- int pos = _find(p_key,exact);
+ int pos = _find(p_key, exact);
if (exact) {
- _data[pos].value=p_val;
+ _data[pos].value = p_val;
return pos;
}
- _data.insert(pos,_Pair(p_key,p_val));
+ _data.insert(pos, _Pair(p_key, p_val));
return pos;
}
- bool has(const T& p_val) const {
+ bool has(const T &p_val) const {
- return _find_exact(p_val)!=-1;
+ return _find_exact(p_val) != -1;
}
- void erase(const T& p_val) {
+ void erase(const T &p_val) {
int pos = _find_exact(p_val);
- if (pos<0)
+ if (pos < 0)
return;
_data.remove(pos);
}
- int find(const T& p_val) const {
+ int find(const T &p_val) const {
return _find_exact(p_val);
-
}
- int find_nearest(const T& p_val) const {
+ int find_nearest(const T &p_val) const {
bool exact;
- return _find(p_val,exact);
-
+ return _find(p_val, exact);
}
_FORCE_INLINE_ int size() const { return _data.size(); }
_FORCE_INLINE_ bool empty() const { return _data.empty(); }
-
const _Pair *get_array() const {
return _data.ptr();
@@ -163,55 +156,46 @@ public:
return _data.ptr();
}
-
- const V& getv(int p_index) const {
+ const V &getv(int p_index) const {
return _data[p_index].value;
}
- V& getv(int p_index) {
+ V &getv(int p_index) {
return _data[p_index].value;
}
-
- const T& getk(int p_index) const {
+ const T &getk(int p_index) const {
return _data[p_index].key;
}
- T& getk(int p_index) {
+ T &getk(int p_index) {
return _data[p_index].key;
}
-
- inline const V& operator[](const T& p_key) const {
+ inline const V &operator[](const T &p_key) const {
int pos = _find_exact(p_key);
- if (pos<0) {
- const T& aux=*((T*)0); //nullreturn
- ERR_FAIL_COND_V(pos<1,aux);
+ if (pos < 0) {
+ const T &aux = *((T *)0); //nullreturn
+ ERR_FAIL_COND_V(pos < 1, aux);
}
return _data[pos].value;
}
-
-
- inline V& operator[](const T& p_key) {
+ inline V &operator[](const T &p_key) {
int pos = _find_exact(p_key);
- if (pos<0) {
+ if (pos < 0) {
V val;
- pos = insert(p_key,val);
-
+ pos = insert(p_key, val);
}
return _data[pos].value;
}
-
-
-
};
#endif // VMAP_H