summaryrefslogtreecommitdiff
path: root/core/vset.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/vset.h')
-rw-r--r--core/vset.h63
1 files changed, 28 insertions, 35 deletions
diff --git a/core/vset.h b/core/vset.h
index e0b5181263..e7e204115f 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