removed MPOOL from some template classes
This commit is contained in:
		| @ -76,15 +76,15 @@ struct HashListResizer | |||||||
| /// For a hash value of hc, this->nodes[hc * 2] points to the first node and | /// 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.      | /// 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 | class HashList: public Mmged | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef LinkedList<T,MPOOL> DatumList; | 	typedef LinkedList<T,COMPARATOR> DatumList; | ||||||
| 	typedef typename DatumList::Node Node; | 	typedef typename DatumList::Node Node; | ||||||
| 	typedef typename DatumList::Iterator Iterator; | 	typedef typename DatumList::Iterator Iterator; | ||||||
| 	typedef typename DatumList::Visiter Visiter; | 	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 HashListHasher<T> DefaultHasher; | ||||||
| 	typedef HashListComparator<T> DefaultComparator; | 	typedef HashListComparator<T> DefaultComparator; | ||||||
| @ -171,7 +171,7 @@ public: | |||||||
|  |  | ||||||
| 			// placement new | 			// placement new | ||||||
| 			this->datum_list = new(list.getMmgr())  | 			this->datum_list = new(list.getMmgr())  | ||||||
| 				DatumList (list.getMmgr(), list.datum_list->getMPBlockSize()); | 				DatumList (list.getMmgr(), list.getMpool().getBlockSize()); | ||||||
| 		} | 		} | ||||||
| 		catch (...)  | 		catch (...)  | ||||||
| 		{ | 		{ | ||||||
| @ -223,6 +223,11 @@ public: | |||||||
| 		return this->datum_list->getMpool (); | 		return this->datum_list->getMpool (); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	const Mpool& getMpool() const | ||||||
|  | 	{ | ||||||
|  | 		return this->datum_list->getMpool (); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	SelfType& operator= (const SelfType& list) | 	SelfType& operator= (const SelfType& list) | ||||||
| 	{ | 	{ | ||||||
| 		this->clear (); | 		this->clear (); | ||||||
| @ -395,7 +400,23 @@ public: | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename MT, typename MHASHER, typename MCOMPARATOR> | 	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; | 		MHASHER hash; | ||||||
| 		Node* b = this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity); | 		Node* b = this->heterofind_node<MT,MCOMPARATOR> (datum, hash(datum) % this->node_capacity); | ||||||
| @ -419,6 +440,20 @@ public: | |||||||
| 		return this->find_node (datum); | 		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) | 	Node* insert (const T& datum) | ||||||
| 	{ | 	{ | ||||||
| 		return this->insert_value (datum, false); | 		return this->insert_value (datum, false); | ||||||
|  | |||||||
| @ -72,12 +72,12 @@ struct HashTableResizer | |||||||
|  |  | ||||||
| typedef HashListResizer 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 | class HashTable: public Mmged | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	typedef Couple<K,V> Pair; | 	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 HashTableHasher<K> DefaultHasher; | ||||||
| 	typedef HashTableComparator<K> DefaultComparator; | 	typedef HashTableComparator<K> DefaultComparator; | ||||||
| @ -85,7 +85,7 @@ public: | |||||||
|  |  | ||||||
| 	struct PairHasher | 	struct PairHasher | ||||||
| 	{ | 	{ | ||||||
| 		qse_size_t operator() (const Pair& p) | 		qse_size_t operator() (const Pair& p) const | ||||||
| 		{ | 		{ | ||||||
| 			HASHER hasher; | 			HASHER hasher; | ||||||
| 			return hasher (p.key); | 			return hasher (p.key); | ||||||
| @ -94,7 +94,7 @@ public: | |||||||
|  |  | ||||||
| 	struct PairComparator | 	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; | 			COMPARATOR comparator; | ||||||
| 			return comparator (p1.key, p2.key); | 			return comparator (p1.key, p2.key); | ||||||
| @ -103,15 +103,26 @@ public: | |||||||
|  |  | ||||||
| 	struct PairHeteroComparator | 	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; | 			COMPARATOR is_equal; | ||||||
| 			return is_equal (p1, p2.key); | 			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::Node PairNode; | ||||||
|  | 	typedef typename PairList::Iterator Iterator; | ||||||
|  |  | ||||||
| 	enum | 	enum | ||||||
| 	{ | 	{ | ||||||
| @ -140,6 +151,16 @@ public: | |||||||
| 		return *this; | 		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) | 	Pair* insert (const K& key, const V& value) | ||||||
| 	{ | 	{ | ||||||
| 		PairNode* node = this->pair_list.insert (Pair(key, value)); | 		PairNode* node = this->pair_list.insert (Pair(key, value)); | ||||||
| @ -156,9 +177,16 @@ public: | |||||||
|  |  | ||||||
| 	Pair* update (const K& key, const V& value) | 	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; | 		if (!node) return QSE_NULL; | ||||||
| 		return &node->value; | 		Pair& pair = node->value; | ||||||
|  | 		pair.value = value; | ||||||
|  | 		return &pair; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	Pair* search (const K& key) | 	Pair* search (const K& key) | ||||||
| @ -175,6 +203,31 @@ public: | |||||||
| 		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 () | 	void clear () | ||||||
| 	{ | 	{ | ||||||
| 		// TODO: accept new capacity. | 		// TODO: accept new capacity. | ||||||
| @ -186,6 +239,12 @@ public: | |||||||
| 		return this->pair_list.getSize (); | 		return this->pair_list.getSize (); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	Iterator getIterator (qse_size_t index = 0) | ||||||
|  | 	{ | ||||||
|  | 		return this->pair_list.getIterator (index); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	PairList pair_list; | 	PairList pair_list; | ||||||
| }; | }; | ||||||
| @ -213,90 +272,6 @@ public: | |||||||
| 		MIN_LOAD_FACTOR = 20 | 		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: | protected: | ||||||
| 	Bucket** allocate_bucket (Mmgr* mm, qse_size_t bs, qse_size_t mpb_size) const | 	Bucket** allocate_bucket (Mmgr* mm, qse_size_t bs, qse_size_t mpb_size) const | ||||||
| 	{ | 	{ | ||||||
| @ -816,10 +791,6 @@ public: | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	//Iterator getIterator () |  | ||||||
| 	//{ |  | ||||||
| 	//} |  | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	mutable qse_size_t  pair_count; | 	mutable qse_size_t  pair_count; | ||||||
| 	mutable qse_size_t  bucket_size; | 	mutable qse_size_t  bucket_size; | ||||||
|  | |||||||
| @ -34,14 +34,14 @@ | |||||||
| QSE_BEGIN_NAMESPACE(QSE) | 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 | class LinkedListNode | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	friend class LinkedList<T,MPOOL,COMPARATOR>; | 	friend class LinkedList<T,COMPARATOR>; | ||||||
| 	typedef LinkedListNode<T,MPOOL,COMPARATOR> SelfType; | 	typedef LinkedListNode<T,COMPARATOR> SelfType; | ||||||
|  |  | ||||||
| 	T value; // you can use this variable or accessor functions below | 	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 { | class LinkedListIterator { | ||||||
| public: | public: | ||||||
| 	friend class LinkedList<T,MPOOL,COMPARATOR>; | 	friend class LinkedList<T,COMPARATOR>; | ||||||
| 	typedef LinkedListNode<T,MPOOL,COMPARATOR> Node; | 	typedef LinkedListNode<T,COMPARATOR> Node; | ||||||
| 	typedef LinkedListIterator<T,MPOOL,COMPARATOR> SelfType; | 	typedef LinkedListIterator<T,COMPARATOR> SelfType; | ||||||
|  |  | ||||||
| 	LinkedListIterator (): current(QSE_NULL) {} | 	LinkedListIterator (): current(QSE_NULL) {} | ||||||
| 	LinkedListIterator (Node* node): current(node) {} | 	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: | public: | ||||||
| 	typedef LinkedList<T,MPOOL,COMPARATOR> SelfType; | 	typedef LinkedList<T,COMPARATOR> SelfType; | ||||||
| 	typedef LinkedListNode<T,MPOOL,COMPARATOR> Node; | 	typedef LinkedListNode<T,COMPARATOR> Node; | ||||||
| 	typedef LinkedListIterator<T,MPOOL,COMPARATOR> Iterator; | 	typedef LinkedListIterator<T,COMPARATOR> Iterator; | ||||||
|  |  | ||||||
| 	typedef Mpool DefaultMpool; |  | ||||||
| 	typedef LinkedListComparator<T> DefaultComparator; | 	typedef LinkedListComparator<T> DefaultComparator; | ||||||
|  |  | ||||||
| 	struct Visiter | 	struct Visiter | ||||||
| @ -276,6 +275,11 @@ public: | |||||||
| 		return this->mp; | 		return this->mp; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	const Mpool& getMpool () const | ||||||
|  | 	{ | ||||||
|  | 		return this->mp; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	qse_size_t getSize () const  | 	qse_size_t getSize () const  | ||||||
| 	{ | 	{ | ||||||
| 		return this->node_count; | 		return this->node_count; | ||||||
| @ -696,7 +700,7 @@ public: | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| protected: | protected: | ||||||
| 	MPOOL       mp; | 	Mpool       mp; | ||||||
| 	COMPARATOR  comparator; | 	COMPARATOR  comparator; | ||||||
| 	Node*       head_node; | 	Node*       head_node; | ||||||
| 	Node*       tail_node; | 	Node*       tail_node; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user