📄 hash_map
字号:
}
// mutators
void swap(hash_map% _Right)
{ // exchange contents with _Right
_Mybase_t::swap(_Right);
}
// interfaces
public:
virtual System::Object^ Clone() override
{ // clone the vector
return (gcnew _Mytype_t(*this));
}
};
//
// TEMPLATE FUNCTION swap
//
template<typename _Key_t,
typename _Mapped_t> inline
void swap(cliext::hash_map<_Key_t, _Mapped_t>% _Left,
cliext::hash_map<_Key_t, _Mapped_t>% _Right)
{ // swap two hash_maps
_Left.swap(_Right);
}
namespace impl {
//
// TEMPLATE CLASS hash_multimap_base0
//
template<typename _Key_t,
typename _Mapped_t>
ref class hash_multimap_base0
: public hash<
hash_map_traits<_Key_t, _Mapped_t, true> >,
System::Collections::Generic::ICollection<
System::Collections::Generic
::KeyValuePair<_Key_t, _Mapped_t>>
{ // ordered red-black tree of unique keys + values
public:
// types
typedef hash_multimap_base0<_Key_t, _Mapped_t>
_Mytype_t;
typedef hash<
hash_map_traits<_Key_t, _Mapped_t, true> > _Mybase_t;
typedef _STLCLR GenericPair<_Key_t, _Mapped_t> _Object_t;
typedef _Key_t key_type;
typedef _Mapped_t mapped_type;
typedef System::Collections::Generic::KeyValuePair<_Key_t, _Mapped_t>
_Mykvpair_t;
typedef cli::array<_Mykvpair_t> _Mykvarray_t;
// basics
hash_multimap_base0()
: _Mybase_t()
{ // construct empty hash_map from defaults
}
hash_multimap_base0(hash_multimap_base0% _Right)
: _Mybase_t((_Mybase_t%)_Right)
{ // construct by copying a list
}
hash_multimap_base0% operator=(hash_multimap_base0% _Right)
{ // assign
_Mybase_t::operator=(_Right);
return (*this);
}
// constructors
explicit hash_multimap_base0(key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct empty hash_map from comparator
}
hash_multimap_base0(key_compare^ _Pred, hasher^ _Hasher)
: _Mybase_t(_Pred, _Hasher)
{ // construct with specified compare and hash
}
template<typename _Iter_t>
hash_multimap_base0(_Iter_t _First, _Iter_t _Last)
: _Mybase_t()
{ // construct hash_map from [_First, _Last), default comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
hash_multimap_base0(_Iter_t _First, _Iter_t _Last, key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct hash_map from [_First, _Last), comparator
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
hash_multimap_base0(_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);
}
// interfaces
private:
property size_type Count_kvpair
{ // element count
virtual size_type get() sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>
::Count::get
{ // get element count
return (size());
}
};
property bool IsReadOnly_kvpair
{ // test if read only
virtual bool get() sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>
::IsReadOnly::get
{ // test if read only
return (false);
}
};
virtual void CopyTo(_Mykvarray_t^ _Dest, int _First) sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>::CopyTo
{ // copy to _Dest, beginning at _First
node_type^ _Node = head_node();
for (int _Idx = size(); 0 <= --_Idx; )
{ // copy back to front
_Node = _Node->prev_node();
_Dest[_First + _Idx] = _Mykvpair_t(_Node->_Value->first,
_Node->_Value->second);
}
}
virtual System::Collections::Generic::IEnumerator<_Mykvpair_t>^
GetEnumerator() sealed
= System::Collections::Generic::IEnumerable<_Mykvpair_t>
::GetEnumerator
{ // get enumerator for the container
return (gcnew HashKVPEnumerator<
_Key_t, _Mapped_t, _Object_t^>(front_node()));
}
virtual void Add(_Mykvpair_t _Kvpair) sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>::Add
{ // add element with value _Kvpair
insert_node(gcnew _Object_t(_Kvpair.Key, _Kvpair.Value), nullptr);
}
virtual void Clear_dictionary() sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>::Clear
{ // erase all elements
clear();
}
virtual bool Contains(_Mykvpair_t _Kvpair) sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>::Contains
{ // search for element matching value _Kvpair
_Object_t^ _Val = gcnew _Object_t(_Kvpair.Key, _Kvpair.Value);
for (node_type^ _Node = front_node(); _Node != head_node();
_Node = _Node->next_node())
if (((System::Object^)_Val)->Equals(
(System::Object^)_Node->_Value))
return (true);
return (false);
}
virtual bool Remove(_Mykvpair_t _Kvpair) sealed
= System::Collections::Generic::ICollection<_Mykvpair_t>::Remove
{ // remove first element matching key _Keypair
for (node_type^ _Node = front_node(); _Node != head_node();
_Node = _Node->next_node())
if (((System::Object^)_Kvpair.Key)->Equals(
(System::Object^)_Node->_Value->first)
&& ((System::Object^)_Kvpair.Value)->Equals(
(System::Object^)_Node->_Value->second))
{ // found a match, remove it
erase_node(_Node);
return (true);
}
return (false);
}
};
//
// TEMPLATE CLASS hash_multimap_base
//
template<typename _Key_t,
typename _Mapped_t>
ref class hash_multimap_base
: public hash_multimap_base0<_Key_t, _Mapped_t>,
System::Collections::Generic::ICollection<
_STLCLR GenericPair<_Key_t, _Mapped_t>^>,
System::Collections::Generic::IEnumerable<
_STLCLR GenericPair<_Key_t, _Mapped_t>^>
{ // hash table of non-unique keys + values
public:
// types
typedef hash_multimap_base<_Key_t, _Mapped_t> _Mytype_t;
typedef hash_multimap_base0<_Key_t, _Mapped_t> _Mybase_t;
typedef _STLCLR GenericPair<_Key_t, _Mapped_t> _Object_t;
typedef _Key_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_multimap_base()
: _Mybase_t()
{ // construct empty hash_multimap from defaults
}
hash_multimap_base(hash_multimap_base% _Right)
: _Mybase_t(_Right)
{ // construct by copying a hash_multimap
}
hash_multimap_base% operator=(hash_multimap_base% _Right)
{ // assign
_Mybase_t::operator=(_Right);
return (*this);
}
// constructors
explicit hash_multimap_base(key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct empty hash_multimap from compare
}
hash_multimap_base(key_compare^ _Pred, hasher^ _Hasher)
: _Mybase_t(_Pred, _Hasher)
{ // construct with specified compare and hash
}
template<typename _Iter_t>
hash_multimap_base(_Iter_t _First, _Iter_t _Last)
: _Mybase_t()
{ // construct hash_multimap from [_First, _Last), defaults
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
hash_multimap_base(_Iter_t _First, _Iter_t _Last,
key_compare^ _Pred)
: _Mybase_t(_Pred)
{ // construct hash_multimap from [_First, _Last), compare
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
template<typename _Iter_t>
hash_multimap_base(_Iter_t _First, _Iter_t _Last,
key_compare^ _Pred, hasher^ _Hasher)
: _Mybase_t(_Pred, _Hasher)
{ // construct hash_multimap from [_First, _Last), compare and hash
for (; _First != _Last; ++_First)
insert((value_type)*_First);
}
// converters
static value_type make_value(key_type _Key, mapped_type _Mapped)
{ // make a value_type
return (gcnew _Object_t(_Key, _Mapped));
}
// mutators
iterator insert(value_type _Val)
{ // try to insert node with value _Val, return iterator
_Pairnb _Ans = insert_node(_Val, nullptr);
return (make_iterator(_Ans.first));
}
iterator insert(iterator, value_type _Val) new
{ // insert a key value, with hint
_Pairnb _Ans = insert_node(_Val, nullptr); // ignore hint
return (make_iterator(_Ans.first));
}
template<typename _Iter_t>
void insert(_Iter_t _First, _Iter_t _Last)
{ // insert [_First, _Last) one at a time
_Mybase_t::insert(_First, _Last);
}
void insert(_Myenum_it^ _Right) new
{ // insert enumerable
_Mybase_t::insert(_Right);
}
// interfaces
private:
property size_type Count_generic
{ // element count
virtual size_type get() sealed
= System::Collections::Generic::ICollection<_Value_t>
::Count::get
{ // get element count
return (size());
}
};
property bool IsReadOnly
{ // test if read only
virtual bool get() sealed
= System::Collections::Generic::ICollection<_Value_t>
::IsReadOnly::get
{ // test if read only
return (false);
}
};
virtual void CopyTo(_Myarray_t^ _Dest, int _First) sealed
= System::Collections::Generic::ICollection<_Value_t>::CopyTo
{ // copy to _Dest, beginning at _First
node_type^ _Node = head_node();
for (int _Idx = size(); 0 <= --_Idx; )
{ // copy back to front
_Node = _Node->prev_node();
_Dest[_First + _Idx] = _Node->_Value;
}
}
virtual System::Collections::Generic::IEnumerator<_Value_t>^
GetEnumerator() sealed
= System::Collections::Generic::IEnumerable<_Value_t>::GetEnumerator
{ // get enumerator for the container
return (gcnew _STLCLR HashEnumerator<_Key_t, _Value_t>(
front_node()));
}
virtual void Add(value_type _Val) sealed
= System::Collections::Generic::ICollection<_Value_t>::Add
{ // add element with value _Val
insert_node(_Val, nullptr);
}
virtual void Clear() sealed
= System::Collections::Generic::ICollection<_Value_t>::Clear
{ // erase all elements
clear();
}
virtual bool Contains(value_type _Val) sealed
= System::Collections::Generic::ICollection<_Value_t>::Contains
{ // search for element matching value _Val
for (node_type^ _Node = front_node(); _Node != head_node();
_Node = _Node->next_node())
if (((System::Object^)_Val)->Equals(
(System::Object^)_Node->_Value))
return (true);
return (false);
}
virtual bool Remove(value_type _Val) sealed
= System::Collections::Generic::ICollection<_Value_t>::Remove
{ // remove first element matching value _Val
for (node_type^ _Node = front_node(); _Node != head_node();
_Node = _Node->next_node())
if (((System::Object^)_Val->first)->Equals(
(System::Object^)_Node->_Value->first)
&& ((System::Object^)_Val->second)->Equals(
(System::Object^)_Node->_Value->second))
{ // found a match, remove it
erase_node(_Node);
return (true);
}
return (false);
}
};
//
// TEMPLATE CLASS hash_multimap_select
//
template<typename _Key1_t,
typename _Mapped_t,
bool _Is_ref_key,
bool _Is_ref_mapped>
ref class hash_multimap_select
: public hash_multimap_base<_Key1_t, _Mapped_t>
{ // ordered red-black tree of non-unique keys + values
public:
// types
typedef _Key1_t _Gkey_t;
typedef _Mapped_t _Gmapped_t;
typedef hash_multimap_select<_Key1_t, _Mapped_t,
_Is_ref_key, _Is_ref_mapped>
_Mytype_t;
typedef hash_multimap_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_multimap_select()
: _Mybase_t()
{ // construct empty map from defaults
}
hash_multimap_select(hash_multimap_select% _Right)
: _Mybase_t((_Mybase_t%)_Right)
{ // construct by copying a hash_multimap
}
hash_multimap_select% operator=(hash_multimap_select% _Right)
{ // assign
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -