removed MPOOL from some template classes
This commit is contained in:
parent
ae717e066e
commit
ca8956366c
@ -76,15 +76,15 @@ struct HashListResizer
|
||||
/// For a hash value of hc, this->nodes[hc * 2] points to the first node and
|
||||
/// this->nodes[hc * 2 + 1] ponits to the last node.
|
||||
|
||||
template <typename T, typename MPOOL = Mpool, typename HASHER = HashListHasher<T>, typename COMPARATOR = HashListComparator<T>, typename RESIZER = HashListResizer >
|
||||
template <typename T, typename HASHER = HashListHasher<T>, typename COMPARATOR = HashListComparator<T>, typename RESIZER = HashListResizer >
|
||||
class HashList: public Mmged
|
||||
{
|
||||
public:
|
||||
typedef LinkedList<T,MPOOL> DatumList;
|
||||
typedef LinkedList<T,COMPARATOR> DatumList;
|
||||
typedef typename DatumList::Node Node;
|
||||
typedef typename DatumList::Iterator Iterator;
|
||||
typedef typename DatumList::Visiter Visiter;
|
||||
typedef HashList<T,MPOOL,HASHER,COMPARATOR,RESIZER> SelfType;
|
||||
typedef HashList<T,HASHER,COMPARATOR,RESIZER> SelfType;
|
||||
|
||||
typedef HashListHasher<T> DefaultHasher;
|
||||
typedef HashListComparator<T> DefaultComparator;
|
||||
@ -171,7 +171,7 @@ public:
|
||||
|
||||
// placement new
|
||||
this->datum_list = new(list.getMmgr())
|
||||
DatumList (list.getMmgr(), list.datum_list->getMPBlockSize());
|
||||
DatumList (list.getMmgr(), list.getMpool().getBlockSize());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -223,6 +223,11 @@ public:
|
||||
return this->datum_list->getMpool ();
|
||||
}
|
||||
|
||||
const Mpool& getMpool() const
|
||||
{
|
||||
return this->datum_list->getMpool ();
|
||||
}
|
||||
|
||||
SelfType& operator= (const SelfType& list)
|
||||
{
|
||||
this->clear ();
|
||||
@ -395,7 +400,23 @@ public:
|
||||
}
|
||||
|
||||
template <typename MT, typename MHASHER, typename MCOMPARATOR>
|
||||
Node* heterofindValue(const MT& datum)
|
||||
const Node* heterofindNode (const MT& datum) const
|
||||
{
|
||||
MHASHER hash;
|
||||
return this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity);
|
||||
}
|
||||
|
||||
template <typename MT, typename MHASHER, typename MCOMPARATOR>
|
||||
T* heterofindValue(const MT& datum)
|
||||
{
|
||||
MHASHER hash;
|
||||
Node* b = this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity);
|
||||
if (!b) return QSE_NULL;
|
||||
return &b->value;
|
||||
}
|
||||
|
||||
template <typename MT, typename MHASHER, typename MCOMPARATOR>
|
||||
const T* heterofindValue(const MT& datum) const
|
||||
{
|
||||
MHASHER hash;
|
||||
Node* b = this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity);
|
||||
@ -419,6 +440,20 @@ public:
|
||||
return this->find_node (datum);
|
||||
}
|
||||
|
||||
template <typename MT, typename MHASHER, typename MCOMPARATOR>
|
||||
Node* heterosearch (const MT& datum)
|
||||
{
|
||||
MHASHER hash;
|
||||
return this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity);
|
||||
}
|
||||
|
||||
template <typename MT, typename MHASHER, typename MCOMPARATOR>
|
||||
const Node* heterosearch (const MT& datum) const
|
||||
{
|
||||
MHASHER hash;
|
||||
return this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity);
|
||||
}
|
||||
|
||||
Node* insert (const T& datum)
|
||||
{
|
||||
return this->insert_value (datum, false);
|
||||
|
@ -72,12 +72,12 @@ struct HashTableResizer
|
||||
|
||||
typedef HashListResizer HashTableResizer;
|
||||
|
||||
template <typename K, typename V, typename MPOOL = Mpool, typename HASHER = HashTableHasher<K>, typename COMPARATOR = HashTableComparator<K>, typename RESIZER = HashTableResizer>
|
||||
template <typename K, typename V, typename HASHER = HashTableHasher<K>, typename COMPARATOR = HashTableComparator<K>, typename RESIZER = HashTableResizer>
|
||||
class HashTable: public Mmged
|
||||
{
|
||||
public:
|
||||
typedef Couple<K,V> Pair;
|
||||
typedef HashTable<K,V,MPOOL,HASHER,COMPARATOR,RESIZER> SelfType;
|
||||
typedef HashTable<K,V,HASHER,COMPARATOR,RESIZER> SelfType;
|
||||
|
||||
typedef HashTableHasher<K> DefaultHasher;
|
||||
typedef HashTableComparator<K> DefaultComparator;
|
||||
@ -85,7 +85,7 @@ public:
|
||||
|
||||
struct PairHasher
|
||||
{
|
||||
qse_size_t operator() (const Pair& p)
|
||||
qse_size_t operator() (const Pair& p) const
|
||||
{
|
||||
HASHER hasher;
|
||||
return hasher (p.key);
|
||||
@ -94,7 +94,7 @@ public:
|
||||
|
||||
struct PairComparator
|
||||
{
|
||||
qse_size_t operator() (const Pair& p1, const Pair& p2)
|
||||
qse_size_t operator() (const Pair& p1, const Pair& p2) const
|
||||
{
|
||||
COMPARATOR comparator;
|
||||
return comparator (p1.key, p2.key);
|
||||
@ -103,15 +103,26 @@ public:
|
||||
|
||||
struct PairHeteroComparator
|
||||
{
|
||||
qse_size_t operator() (const K& p1, const Pair& p2)
|
||||
qse_size_t operator() (const K& p1, const Pair& p2) const
|
||||
{
|
||||
COMPARATOR is_equal;
|
||||
return is_equal (p1, p2.key);
|
||||
}
|
||||
};
|
||||
|
||||
typedef HashList<Pair,MPOOL,PairHasher,PairComparator,RESIZER> PairList;
|
||||
template <typename MK, typename MCOMPARATOR>
|
||||
struct MHeteroComparator
|
||||
{
|
||||
qse_size_t operator() (const MK& p1, const Pair& p2) const
|
||||
{
|
||||
MCOMPARATOR is_equal;
|
||||
return is_equal (p1, p2.key);
|
||||
}
|
||||
};
|
||||
|
||||
typedef HashList<Pair,PairHasher,PairComparator,RESIZER> PairList;
|
||||
typedef typename PairList::Node PairNode;
|
||||
typedef typename PairList::Iterator Iterator;
|
||||
|
||||
enum
|
||||
{
|
||||
@ -140,6 +151,16 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mpool& getMpool ()
|
||||
{
|
||||
return this->datum_list->getMpool();
|
||||
}
|
||||
|
||||
const Mpool& getMpool () const
|
||||
{
|
||||
return this->datum_list->getMpool();
|
||||
}
|
||||
|
||||
Pair* insert (const K& key, const V& value)
|
||||
{
|
||||
PairNode* node = this->pair_list.insert (Pair(key, value));
|
||||
@ -156,15 +177,22 @@ public:
|
||||
|
||||
Pair* update (const K& key, const V& value)
|
||||
{
|
||||
PairNode* node = this->pair_list.update (Pair(key, value));
|
||||
|
||||
//PairNode* node = this->pair_list.update (Pair(key, value));
|
||||
//if (!node) return QSE_NULL;
|
||||
//return &node->value;
|
||||
|
||||
PairNode* node = this->pair_list.template heterofindNode<K,HASHER,PairHeteroComparator> (key);
|
||||
if (!node) return QSE_NULL;
|
||||
return &node->value;
|
||||
Pair& pair = node->value;
|
||||
pair.value = value;
|
||||
return &pair;
|
||||
}
|
||||
|
||||
Pair* search (const K& key)
|
||||
{
|
||||
//PairNode* node = this->pair_list.update (Pair(key));
|
||||
PairNode* node = this->pair_list.template heterofindNode <K,HASHER,PairHeteroComparator> (key);
|
||||
PairNode* node = this->pair_list.template heterofindNode<K,HASHER,PairHeteroComparator> (key);
|
||||
if (!node) return QSE_NULL;
|
||||
return &node->value;
|
||||
}
|
||||
@ -172,7 +200,32 @@ public:
|
||||
int remove (const K& key)
|
||||
{
|
||||
//return this->pair_list.remove (Pair(key));
|
||||
return this->pair_list.template heteroremove <K,HASHER,PairHeteroComparator> (key);
|
||||
return this->pair_list.template heteroremove<K,HASHER,PairHeteroComparator> (key);
|
||||
}
|
||||
|
||||
template <typename MK, typename MHASHER, typename MCOMPARATOR>
|
||||
Pair* heterosearch (const MK& key)
|
||||
{
|
||||
typedef MHeteroComparator<MK,MCOMPARATOR> MComparator;
|
||||
PairNode* node = this->pair_list.template heterosearch<MK,MHASHER,MComparator> (key);
|
||||
if (!node) return QSE_NULL;
|
||||
return &node->value;
|
||||
}
|
||||
|
||||
template <typename MK, typename MHASHER, typename MCOMPARATOR>
|
||||
const Pair* heterosearch (const MK& key) const
|
||||
{
|
||||
typedef MHeteroComparator<MK,MCOMPARATOR> MComparator;
|
||||
PairNode* node = this->pair_list.template heterosearch<MK,MHASHER,MComparator> (key);
|
||||
if (!node) return QSE_NULL;
|
||||
return &node->value;
|
||||
}
|
||||
|
||||
template <typename MK, typename MHASHER, typename MCOMPARATOR>
|
||||
int heteroremove (const MK& key)
|
||||
{
|
||||
typedef MHeteroComparator<MK,MCOMPARATOR> MComparator;
|
||||
return this->pair_list.template heteroremove<MK,MHASHER,MComparator> (key);
|
||||
}
|
||||
|
||||
void clear ()
|
||||
@ -186,6 +239,12 @@ public:
|
||||
return this->pair_list.getSize ();
|
||||
}
|
||||
|
||||
|
||||
Iterator getIterator (qse_size_t index = 0)
|
||||
{
|
||||
return this->pair_list.getIterator (index);
|
||||
}
|
||||
|
||||
protected:
|
||||
PairList pair_list;
|
||||
};
|
||||
@ -213,90 +272,6 @@ public:
|
||||
MIN_LOAD_FACTOR = 20
|
||||
};
|
||||
|
||||
#if 0
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator (): bucket_index(0), bucket_node(QSE_NULL) {}
|
||||
Iterator (qse_size_t index, BucketNode* node): bucket_index(index), bucket_node(node) {}
|
||||
Iterator (const Iterator& it): bucket_index (it.bucket_index), bucket_node(it.bucket_node) {}
|
||||
|
||||
Iterator& operator= (const Iterator& it)
|
||||
{
|
||||
this->bucket_index = it.bucket_index;
|
||||
this->bucket_node = it.bucket_node;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator& operator++ () // prefix increment
|
||||
{
|
||||
QSE_ASSERT (this->isLegit());
|
||||
this->bucket_node = this->bucket_node->getNext();
|
||||
if (!this->bucket_node)
|
||||
{
|
||||
while (this->bucket_index
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator++ (int) // postfix increment
|
||||
{
|
||||
QSE_ASSERT (this->isLegit());
|
||||
Iterator saved (*this);
|
||||
this->current = this->current->getNext(); //++(*this);
|
||||
return saved;
|
||||
}
|
||||
|
||||
Iterator& operator-- () // prefix decrement
|
||||
{
|
||||
QSE_ASSERT (this->isLegit());
|
||||
this->current = this->current->getPrev();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator operator-- (int) // postfix decrement
|
||||
{
|
||||
QSE_ASSERT (this->isLegit());
|
||||
Iterator saved (*this);
|
||||
this->current = this->current->getPrev(); //--(*this);
|
||||
return saved;
|
||||
}
|
||||
|
||||
bool operator== (const Iterator& it) const
|
||||
{
|
||||
return this->bucket_index == it.bucket_index &&
|
||||
this->bucket_node == it.bucket_node;
|
||||
}
|
||||
|
||||
bool operator!= (const Iterator& it) const
|
||||
{
|
||||
return this->bucket_index != it.bucket_index ||
|
||||
this->bucket_node != it.bucket_node;
|
||||
}
|
||||
|
||||
bool isLegit () const
|
||||
{
|
||||
// TODO: change this
|
||||
return this->bucket_node != QSE_NULL;
|
||||
}
|
||||
|
||||
T& operator* () // dereference
|
||||
{
|
||||
return this->bucket_node->getValue();
|
||||
}
|
||||
|
||||
const T& operator* () const // dereference
|
||||
{
|
||||
return this->bucket_node->getValue();
|
||||
}
|
||||
|
||||
protected:
|
||||
SelfType* table;
|
||||
qse_size_t bucket_index;
|
||||
BucketNode* bucket_node;
|
||||
};
|
||||
#endif
|
||||
|
||||
protected:
|
||||
Bucket** allocate_bucket (Mmgr* mm, qse_size_t bs, qse_size_t mpb_size) const
|
||||
{
|
||||
@ -816,10 +791,6 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Iterator getIterator ()
|
||||
//{
|
||||
//}
|
||||
|
||||
protected:
|
||||
mutable qse_size_t pair_count;
|
||||
mutable qse_size_t bucket_size;
|
||||
|
@ -34,14 +34,14 @@
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
template <typename T, typename MPOOL, typename COMPARATOR> class LinkedList;
|
||||
template <typename T, typename COMPARATOR> class LinkedList;
|
||||
|
||||
template <typename T, typename MPOOL, typename COMPARATOR>
|
||||
template <typename T, typename COMPARATOR>
|
||||
class LinkedListNode
|
||||
{
|
||||
public:
|
||||
friend class LinkedList<T,MPOOL,COMPARATOR>;
|
||||
typedef LinkedListNode<T,MPOOL,COMPARATOR> SelfType;
|
||||
friend class LinkedList<T,COMPARATOR>;
|
||||
typedef LinkedListNode<T,COMPARATOR> SelfType;
|
||||
|
||||
T value; // you can use this variable or accessor functions below
|
||||
|
||||
@ -79,12 +79,12 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename MPOOL, typename COMPARATOR>
|
||||
template <typename T, typename COMPARATOR>
|
||||
class LinkedListIterator {
|
||||
public:
|
||||
friend class LinkedList<T,MPOOL,COMPARATOR>;
|
||||
typedef LinkedListNode<T,MPOOL,COMPARATOR> Node;
|
||||
typedef LinkedListIterator<T,MPOOL,COMPARATOR> SelfType;
|
||||
friend class LinkedList<T,COMPARATOR>;
|
||||
typedef LinkedListNode<T,COMPARATOR> Node;
|
||||
typedef LinkedListIterator<T,COMPARATOR> SelfType;
|
||||
|
||||
LinkedListIterator (): current(QSE_NULL) {}
|
||||
LinkedListIterator (Node* node): current(node) {}
|
||||
@ -199,16 +199,15 @@ struct LinkedListComparator
|
||||
};
|
||||
|
||||
///
|
||||
/// The LinkedList<T,MPOOL> class provides a template for a doubly-linked list.
|
||||
/// The LinkedList<T,COMPARATOR> class provides a template for a doubly-linked list.
|
||||
///
|
||||
template <typename T, typename MPOOL = Mpool, typename COMPARATOR = LinkedListComparator<T> > class LinkedList: public Mmged
|
||||
template <typename T, typename COMPARATOR = LinkedListComparator<T> > class LinkedList: public Mmged
|
||||
{
|
||||
public:
|
||||
typedef LinkedList<T,MPOOL,COMPARATOR> SelfType;
|
||||
typedef LinkedListNode<T,MPOOL,COMPARATOR> Node;
|
||||
typedef LinkedListIterator<T,MPOOL,COMPARATOR> Iterator;
|
||||
typedef LinkedList<T,COMPARATOR> SelfType;
|
||||
typedef LinkedListNode<T,COMPARATOR> Node;
|
||||
typedef LinkedListIterator<T,COMPARATOR> Iterator;
|
||||
|
||||
typedef Mpool DefaultMpool;
|
||||
typedef LinkedListComparator<T> DefaultComparator;
|
||||
|
||||
struct Visiter
|
||||
@ -276,6 +275,11 @@ public:
|
||||
return this->mp;
|
||||
}
|
||||
|
||||
const Mpool& getMpool () const
|
||||
{
|
||||
return this->mp;
|
||||
}
|
||||
|
||||
qse_size_t getSize () const
|
||||
{
|
||||
return this->node_count;
|
||||
@ -696,7 +700,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
MPOOL mp;
|
||||
Mpool mp;
|
||||
COMPARATOR comparator;
|
||||
Node* head_node;
|
||||
Node* tail_node;
|
||||
|
Loading…
Reference in New Issue
Block a user