panthema / 2006 / SDIOS06 / sdios06 / include / libstdc++ / map (Download File)
#ifndef MAP_
#define MAP_

#include "helpers/redblacktree.h"
#include "utility"

namespace std
{

	template<typename KeyType, typename ValueType>
	class map
	{
	public:
		class TreeValueType : public pair<KeyType, ValueType>
		{
		public:			
			bool operator<(const KeyType& key) const
			{
				return this->first < key;
			}
			
			bool operator<(const TreeValueType& other) const
			{
				return this->first < other.first;
			}			
			
			bool operator==(const KeyType& key) const
			{
				return this->first == key;
			}
			
			TreeValueType(const KeyType& key, const ValueType& val)
				: pair<KeyType, ValueType>(key, val)
			{
			}
		};
		
		typedef private_stuff::RedBlackTree<KeyType, TreeValueType> Tree;
		typedef typename Tree::iterator iterator;
		typedef size_t size_type;
	
		ValueType& operator[] (const KeyType& key)
		{
			iterator i = tree.find(key);
			if(i == end()) {
				i = tree.insert(key, TreeValueType(key, ValueType()));
			}
			
			return i->second;	
		}

		iterator find(const KeyType& key)
		{
			return tree.find(key);
		}
		
		iterator begin()
		{
			return tree.begin();
		}
		
		iterator end()
		{
			return tree.end();
		}
		
		size_type size() const
		{
			return tree.size;
		}
	
	private:
		Tree tree;
	};
}

#endif /*MAP_*/
RSS 2.0 Weblog Feed Atom 1.0 Weblog Feed Valid XHTML 1.1 Valid CSS (2.1)
Copyright 2005-2014 Timo Bingmann - Impressum