Add CWeaponMgr

Former-commit-id: 28983db847
This commit is contained in:
Henrique Gemignani Passos Lima
2022-11-10 04:06:24 +02:00
parent a6ee5c2836
commit c3e6ee87e3
7 changed files with 126 additions and 8 deletions

View File

@@ -18,16 +18,20 @@ private:
typedef red_black_tree< K, value_type, 0, select1st< value_type >, Cmp, Alloc > rep_type;
public:
// typedef typename rep_type::iterator iterator;
typedef typename rep_type::iterator iterator;
typedef typename rep_type::const_iterator const_iterator;
void insert(const value_type& item) { inner.insert(item); }
iterator insert(const value_type& item) { return inner.insert(item); }
const_iterator begin() const { return inner.begin(); }
const_iterator end() const { return inner.end(); }
iterator find(const K& key) { return inner.find(key); }
const_iterator find(const K& key) const { return inner.find(key); }
void erase(iterator it) { inner.erase(it); }
rep_type& get_inner() { return inner; } // hack for CWeaponMgr inlining depth
private:
rep_type inner;
};

View File

@@ -29,6 +29,7 @@ enum node_color {
void rbtree_rebalance(void*, void*);
void* rbtree_traverse_forward(const void*, void*);
void* rbtree_rebalance_for_erase(void* header_void, void* node_void);
template < typename T, typename P, int U, typename S = select1st< P >, typename Cmp = less< T >,
typename Alloc = rmemory_allocator >
@@ -45,6 +46,9 @@ private:
: mLeft(left), mRight(right), mParent(parent), mColor(color) {
construct(get_value(), value);
}
~node() {
get_value()->~P();
}
P* get_value() { return reinterpret_cast< P* >(&mValue); }
const P* get_value() const { return reinterpret_cast< const P* >(&mValue); }
@@ -106,6 +110,10 @@ public:
};
struct iterator : public const_iterator {
iterator(node* node, const header* header, bool b) : const_iterator(node, header, b) {}
P* operator->() { return mNode->get_value(); }
P* operator*() { return mNode->get_value(); }
node* get_node() { return mNode; }
};
red_black_tree() : x0_(0), x1_(0), x4_count(0) {}
@@ -144,6 +152,35 @@ public:
return const_iterator(needle, &x8_header, false);
}
iterator find(const T& key) {
node* n = x8_header.get_root();
node* needle = nullptr;
while (n != nullptr) {
if (!x2_cmp(x3_selector(*n->get_value()), key)) {
needle = n;
n = n->get_left();
} else {
n = n->get_right();
}
}
bool noResult = false;
if (needle == nullptr || x2_cmp(key, x3_selector(*needle->get_value()))) {
noResult = true;
}
if (noResult) {
needle = nullptr;
}
return iterator(needle, &x8_header, false);
}
iterator erase(iterator it) {
node* node = it.get_node();
++it;
free_node(rebalance_for_erase(node));
x4_count--;
return it;
}
void clear() {
node* root = x8_header.get_root();
if (root != nullptr) {
@@ -186,6 +223,8 @@ private:
}
void rebalance(node* n) { rbtree_rebalance(&x8_header, n); }
node* rebalance_for_erase(node* n) { return static_cast<node*>(rbtree_rebalance_for_erase(&x8_header, n)); }
};
static bool kUnknownValueNewRoot = true;