diff options
| author | Rémi Verschelde | 2017-03-05 16:44:50 +0100 |
|---|---|---|
| committer | Rémi Verschelde | 2017-03-05 16:44:50 +0100 |
| commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
| tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/vset.h | |
| parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) | |
| download | godot-5dbf180.tar.gz godot-5dbf180.tar.zst godot-5dbf180.zip | |
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/vset.h')
| -rw-r--r-- | core/vset.h | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/core/vset.h b/core/vset.h index e0b518126..e7e204115 100644 --- a/core/vset.h +++ b/core/vset.h @@ -32,60 +32,57 @@ #include "typedefs.h" #include "vector.h" -template<class T> +template <class T> class VSet { - Vector<T> _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 T *a=&_data[0]; + const T *a = &_data[0]; - while( low <= high ) - { - middle = ( low + high ) / 2; + while (low <= high) { + middle = (low + high) / 2; - if( p_val < a[ middle] ) { + if (p_val < a[middle]) { high = middle - 1; //search low end of array - } else if ( a[middle] < p_val) { + } else if (a[middle] < 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]<p_val) + if (a[middle] < 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 T *a=&_data[0]; + const T *a = &_data[0]; - while( low <= high ) - { - middle = ( low + high ) / 2; + while (low <= high) { + middle = (low + high) / 2; - if( p_val < a[ middle] ) { + if (p_val < a[middle]) { high = middle - 1; //search low end of array - } else if ( a[middle] < p_val) { + } else if (a[middle] < p_val) { low = middle + 1; //search high end of array } else { return middle; @@ -96,50 +93,46 @@ class VSet { } public: - - void insert(const T& p_val) { + void insert(const T &p_val) { bool exact; - int pos = _find(p_val,exact); + int pos = _find(p_val, exact); if (exact) return; - _data.insert(pos,p_val); + _data.insert(pos, p_val); } - 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); - } _FORCE_INLINE_ bool empty() const { return _data.empty(); } _FORCE_INLINE_ int size() const { return _data.size(); } - inline T& operator[](int p_index) { + inline T &operator[](int p_index) { return _data[p_index]; } - inline const T& operator[](int p_index) const { + inline const T &operator[](int p_index) const { return _data[p_index]; } - - }; #endif // VSET_H |
