⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hash_map

📁 C语言库函数的原型,有用的拿去
💻
📖 第 1 页 / 共 5 页
字号:
	{	// ordered red-black tree of unique keys + values
public:
	// types
	typedef _Key1_t^ _Gkey_t;
	typedef _Mapped_t _Gmapped_t;

	typedef hash_map_select<_Key1_t, _Mapped_t, true, false> _Mytype_t;
	typedef hash_map_base<_Gkey_t, _Gmapped_t> _Mybase_t;
//	typedef System::Collections::Generic::IEnumerable<_Value_t> _Myenum_it;
//	typedef _STLCLR GenericPair<_Gkey_t, _Gmapped_t> _Object_t;

	typedef _Key1_t key_type;
	typedef _Mapped_t mapped_type;
//	typedef typename _Traits_t::value_type value_type;
//	typedef typename _Traits_t::key_compare key_compare;
//	typedef typename _Traits_t::key_compare key_compare;
//	typedef typename _Mybase_t::hasher hasher;

//	typedef int size_type;
//	typedef int difference_type;
//	typedef _Value_t value_type;
//	typedef value_type% reference;
//	typedef value_type% const_reference;

//	typedef _Mycont_it generic_container;
//	typedef value_type generic_value;

//	typedef _STLCLR GenericPair<iterator^, bool> pair_iter_bool;
//	typedef _STLCLR GenericPair<iterator^, iterator^> pair_iter_iter;

	// basics
	hash_map_select()
		:	_Mybase_t()
		{	// construct empty map from defaults
		}

	hash_map_select(hash_map_select% _Right)
		:	_Mybase_t((_Mybase_t%)_Right)
		{	// construct by copying a hash_map
		}

	hash_map_select% operator=(hash_map_select% _Right)
		{	// assign
		_Mybase_t::operator=(_Right);
		return (*this);
		}

	// constructors
	explicit hash_map_select(key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct empty map from comparator
		}

	hash_map_select(key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct with specified compare and hash
		}

	template<typename _Iter_t>
		hash_map_select(_Iter_t _First, _Iter_t _Last)
		:	_Mybase_t()
		{	// construct map from [_First, _Last), default comparator
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	template<typename _Iter_t>
		hash_map_select(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct map from [_First, _Last), comparator
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	template<typename _Iter_t>
		hash_map_select(_Iter_t _First, _Iter_t _Last,
			key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct hash_map from [_First, _Last), compare and hash
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	// accessors
	property mapped_type default[key_type]
		{	// get or set subscripted element
		mapped_type get(key_type _Key)
			{	// get _Key element
			_Pairnb _Ans = insert_node(
				gcnew _Object_t(gcnew _Key1_t(_Key)), nullptr);

			return (_Ans.first->_Value->second);
			}

		void set(key_type _Key, mapped_type _Val)
			{	// set _Key element
			node_type^ _Node = insert_node(
				gcnew _Object_t(gcnew _Key1_t(_Key)), nullptr).first;

			_Node->_Value->second = _Val;
			}
		};

	// converters
	static value_type make_value(key_type _Key, mapped_type _Mapped)
		{	// make a value_type
		return (gcnew _Object_t(gcnew _Key1_t(_Key), _Mapped));
		}

	// mutators
	size_type erase(key_type _Keyval) 
		{	// erase element at _Where
		return (_Mybase_t::erase(%_Keyval));
		}

	pair_iter_bool insert(cliext::pair<key_type, mapped_type> _Val) 
		{	// try to insert node with value _Val, return iterator
		_Pairnb _Ans = insert_node(make_value(_Val.first, _Val.second));

		return (pair_iter_bool(iterator(_Ans.first),
			_Ans.second));
		}

	iterator insert(iterator _Where,
		cliext::pair<key_type, mapped_type> _Val) 
		{	// insert a key value, with hint
		return (_Mybase_t::insert(_Where,
			make_value(_Val.first, _Val.second)));
		}

	// searches
	iterator find(key_type _Keyval)
		{	// find an element that matches _Keyval, return iterator
		return (_Mybase_t::find(%_Keyval));
		}

	size_type count(key_type _Keyval)
		{	// count all elements that match _Keyval
		return (_Mybase_t::count(%_Keyval));
		}

	iterator lower_bound(key_type _Keyval)
		{	// find leftmost node not less than _Keyval
		return (_Mybase_t::lower_bound(%_Keyval));
		}

	iterator upper_bound(key_type _Keyval)
		{	// find leftmost node not less than _Keyval
		return (_Mybase_t::upper_bound(%_Keyval));
		}

	pair_iter_iter equal_range(key_type _Keyval)
		{	// find range equivalent to _Keyval
		return (_Mybase_t::equal_range(%_Keyval));
		}
	};

//
// TEMPLATE CLASS hash_map_select: _Key1_t, _Mapped_t REF SPECIALIZATION
//
template<typename _Key1_t,
	typename _Mapped_t>
	ref class hash_map_select<_Key1_t, _Mapped_t, true, true>
	:	public hash_map_base<_Key1_t^, _Mapped_t^>
	{	// ordered red-black tree of unique keys + values
public:
	// types
	typedef _Key1_t^ _Gkey_t;
	typedef _Mapped_t^ _Gmapped_t;

	typedef hash_map_select<_Key1_t, _Mapped_t, true, true> _Mytype_t;
	typedef hash_map_base<_Gkey_t, _Gmapped_t> _Mybase_t;
//	typedef System::Collections::Generic::IEnumerable<_Value_t> _Myenum_it;
//	typedef _STLCLR GenericPair<_Gkey_t, _Gmapped_t> _Object_t;

	typedef _Key1_t key_type;
	typedef _Mapped_t mapped_type;
//	typedef typename _Traits_t::value_type value_type;
//	typedef typename _Traits_t::key_compare key_compare;
//	typedef typename _Traits_t::key_compare key_compare;
//	typedef typename _Mybase_t::hasher hasher;

//	typedef int size_type;
//	typedef int difference_type;
//	typedef _Value_t value_type;
//	typedef value_type% reference;
//	typedef value_type% const_reference;

//	typedef _Mycont_it generic_container;
//	typedef value_type generic_value;

//	typedef _STLCLR GenericPair<iterator^, bool> pair_iter_bool;
//	typedef _STLCLR GenericPair<iterator^, iterator^> pair_iter_iter;

	// basics
	hash_map_select()
		:	_Mybase_t()
		{	// construct empty map from defaults
		}

	hash_map_select(hash_map_select% _Right)
		:	_Mybase_t((_Mybase_t%)_Right)
		{	// construct by copying a hash_map
		}

	hash_map_select% operator=(hash_map_select% _Right)
		{	// assign
		_Mybase_t::operator=(_Right);
		return (*this);
		}

	// constructors
	explicit hash_map_select(key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct empty map from comparator
		}

	hash_map_select(key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct with specified compare and hash
		}

	template<typename _Iter_t>
		hash_map_select(_Iter_t _First, _Iter_t _Last)
		:	_Mybase_t()
		{	// construct map from [_First, _Last), default comparator
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	template<typename _Iter_t>
		hash_map_select(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct map from [_First, _Last), comparator
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	template<typename _Iter_t>
		hash_map_select(_Iter_t _First, _Iter_t _Last,
			key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct hash_map from [_First, _Last), compare and hash
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	// accessors
	property mapped_type default[key_type]
		{	// get or set subscripted element
		mapped_type get(key_type _Key)
			{	// get _Key element
			_Pairnb _Ans = insert_node(
				gcnew _Object_t(gcnew _Key1_t(_Key)), nullptr);

			return (*_Ans.first->_Value->second);
			}

		void set(key_type _Key, mapped_type _Val)
			{	// set _Key element
			node_type^ _Node = insert_node(
				gcnew _Object_t(gcnew _Key1_t(_Key)), nullptr).first;

			_Node->_Value->second = gcnew _Mapped_t(_Val);
			}
		};

	// converters
	static value_type make_value(key_type _Key, mapped_type _Mapped)
		{	// make a value_type
		return (gcnew _Object_t(gcnew _Key1_t(_Key),
			gcnew _Mapped_t(_Mapped)));
		}

	// mutators
	size_type erase(key_type _Keyval) new
		{	// erase element at _Where
		return (_Mybase_t::erase(%_Keyval));
		}

	pair_iter_bool insert(cliext::pair<key_type, mapped_type> _Val) new
		{	// try to insert node with value _Val, return iterator
		_Pairnb _Ans = insert_node(make_value(_Val.first, _Val.second));

		return (pair_iter_bool(iterator(_Ans.first),
			_Ans.second));
		}

	iterator insert(iterator _Where,
		cliext::pair<key_type, mapped_type> _Val) new
		{	// insert a key value, with hint
		return (_Mybase_t::insert(_Where,
			make_value(_Val.first, _Val.second)));
		}

	// searches
	iterator find(key_type _Keyval)
		{	// find an element that matches _Keyval, return iterator
		return (_Mybase_t::find(%_Keyval));
		}

	size_type count(key_type _Keyval)
		{	// count all elements that match _Keyval
		return (_Mybase_t::count(%_Keyval));
		}

	iterator lower_bound(key_type _Keyval)
		{	// find leftmost node not less than _Keyval
		return (_Mybase_t::lower_bound(%_Keyval));
		}

	iterator upper_bound(key_type _Keyval)
		{	// find leftmost node not less than _Keyval
		return (_Mybase_t::upper_bound(%_Keyval));
		}

	pair_iter_iter equal_range(key_type _Keyval)
		{	// find range equivalent to _Keyval
		return (_Mybase_t::equal_range(%_Keyval));
		}
	};
	}	// namespace cliext::impl

//
// TEMPLATE CLASS hash_map
//
template<typename _Key1_t,
	typename _Mapped_t>
	ref class hash_map
	:	public impl::hash_map_select<
			_Key1_t,
			_Mapped_t,
			__is_ref_class(typename _Dehandle<_Key1_t>::type)
				&& !is_handle<_Key1_t>::value,
			__is_ref_class(typename _Dehandle<_Mapped_t>::type)
				&& !is_handle<_Mapped_t>::value>
	{	// ordered red-black tree of unique keys + values
public:
	// types
	typedef hash_map<_Key1_t, _Mapped_t> _Mytype_t;
	typedef impl::hash_map_select<
		_Key1_t,
		_Mapped_t,
		__is_ref_class(typename _Dehandle<_Key1_t>::type)
			&& !is_handle<_Key1_t>::value,
		__is_ref_class(typename _Dehandle<_Mapped_t>::type)
			&& !is_handle<_Mapped_t>::value> _Mybase_t;

//	typedef _Key1_t key_type;
//	typedef _Mapped_t mapped_type;
//	typedef typename _Traits_t::value_type value_type;
//	typedef typename _Traits_t::key_compare key_compare;
//	typedef typename _Traits_t::key_compare key_compare;
//	typedef typename _Mybase_t::hasher hasher;

//	typedef int size_type;
//	typedef int difference_type;
//	typedef _Value_t value_type;
//	typedef value_type% reference;
//	typedef value_type% const_reference;

//	typedef _Mycont_it generic_container;
//	typedef value_type generic_value;

//	typedef _STLCLR GenericPair<iterator^, bool> pair_iter_bool;
//	typedef _STLCLR GenericPair<iterator^, iterator^> pair_iter_iter;

	// basics
	hash_map()
		:	_Mybase_t()
		{	// construct default
		}

	hash_map(hash_map% _Right)
		:	_Mybase_t((_Mybase_t%)_Right)
		{	// construct by copying a hash_map
		}

	hash_map(hash_map^ _Right)
		:	_Mybase_t((_Mybase_t%)*_Right)
		{	// construct by copying a hash_map
		}

	hash_map% operator=(hash_map% _Right)
		{	// assign
		_Mybase_t::operator=(_Right);
		return (*this);
		}

	hash_map% operator=(hash_map^ _Right)
		{	// assign
		_Mybase_t::operator=(*_Right);
		return (*this);
		}

	// constructors
	explicit hash_map(key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct empty map from comparator
		}

	hash_map(key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct with specified compare and hash
		}

	template<typename _Iter_t>
		hash_map(_Iter_t _First, _Iter_t _Last)
		:	_Mybase_t()
		{	// construct map from [_First, _Last), default comparator
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	template<typename _Iter_t>
		hash_map(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct map from [_First, _Last), comparator
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	template<typename _Iter_t>
		hash_map(_Iter_t _First, _Iter_t _Last,
			key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct hash_map from [_First, _Last), compare and hash
		for (; _First != _Last; ++_First)
			insert((value_type)*_First);
		}

	hash_map(_Myenum_it^ _Right)
		:	_Mybase_t()
		{	// construct map from enumeration, default comparator
		for each (value_type _Val in _Right)
			insert(_Val);
		}

	hash_map(_Myenum_it^ _Right,
		key_compare^ _Pred)
		:	_Mybase_t(_Pred)
		{	// construct map from enumeration, comparator
		for each (value_type _Val in _Right)
			insert(_Val);
		}

	hash_map(_Myenum_it^ _Right,
		key_compare^ _Pred, hasher^ _Hasher)
		:	_Mybase_t(_Pred, _Hasher)
		{	// construct map from enumeration, compare and hash
		for each (value_type _Val in _Right)
			insert(_Val);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -