1 // xhash stl/clr header
2 #ifndef _CLI_XHASH_
3  #define _CLI_XHASH_
4 #include <cliext/functional>    // for Binary/UnaryDelegate
5 #include <cliext/list>        // for the sequence container
6
7 namespace cliext {
8 //
9 // TEMPLATE FUNCTION _Hash_key_compare
10 //
11 template<typename _Key_t> inline
12     bool _Hash_key_compare(_Key_t _Left, _Key_t _Right)
13     {    // test if _Left <= _Right
14     return (!(_Right < _Left));
15     }
16
17 inline bool _Hash_key_compare(System::String^ _Left, System::String^ _Right)
18     {    // test if _Left <= _Right for String
19     return (!(_Right->CompareTo(_Left) < 0));
20     }
21
22 //
23 // FUNCTION hash_value
24 //
25 inline int hash_value(System::Object^ _Key)
26     {    // get hash code from object
27     return (_Key->GetHashCode());
28     }
29
30     namespace impl {
31 //
32 // TEMPLATE CLASS hash
33 //
34 template<typename _Traits_t>
35     ref class hash
36     :    public _Traits_t,
37         _STLCLR IHash<
38             typename _Traits_t::key_type,
39             typename _Traits_t::value_type>
40     {    // hash table of elements
41 public:
42     // types
43     typedef hash<_Traits_t> _Mytype_t;
44     typedef _Traits_t _Mybase_t;
45     typedef typename _Traits_t::key_type _Key_t;
46     typedef typename _Traits_t::value_type _Value_t;
47     typedef _STLCLR IHash<_Key_t, _Value_t> _Mycont_it;
48     typedef System::Collections::Generic::IEnumerable<_Value_t> _Myenum_it;
49     typedef cli::array<_Value_t> _Myarray_t;
50
51     typedef list<_Value_t> _Mylist_t;    // the controlled sequence
52     typedef list_node<_Value_t> node_type;
53     typedef cli::array<node_type^> _Myvector_t;    // the hash table
Lines 54 ... 978 are skipped.
979         {    // find an element that matches _Keyval, return iterator
980         return (find(_Keyval));
981         }
982
983     virtual size_type count_virtual(key_type _Keyval) sealed
984         = _Mycont_it::count
985         {    // count all elements that match _Keyval
986         return (count(_Keyval));
987         }
988
989     virtual generic_iterator lower_bound_virtual(key_type _Keyval) sealed
990         = _Mycont_it::lower_bound
991         {    // find leftmost node not less than _Keyval
992         return (lower_bound(_Keyval));
993         }
994
995     virtual generic_iterator upper_bound_virtual(key_type _Keyval) sealed
996         = _Mycont_it::upper_bound
997         {    // find leftmost node greater than _Keyval
998         return (upper_bound(_Keyval));
999         }
1000
1001     virtual generic_pair_iter_iter equal_range_virtual(
1002         key_type _Keyval) sealed
1003             = _Mycont_it::equal_range
1004         {    // find range equivalent to _Keyval
1005         _Pairnn _Ans = equal_range_node(_Keyval);
1006         return (generic_pair_iter_iter(gcnew generic_iterator(_Ans.first),
1007             gcnew generic_iterator(_Ans.second)));
1008         }
1009     };
1010     }    // namespace cliext::impl
1011 //
1012 // TEMPLATE FUNCTION swap
1013 //
1014 template<typename _Traits_t> inline
1015     void swap(cliext::impl::hash<_Traits_t>% _Left,
1016         cliext::impl::hash<_Traits_t>% _Right)
1017     {    // swap two hash objects
1018     _Left.swap(_Right);
1019     }
1020 }    // namespace cliext
1021 #endif // _CLI_XHASH_
1022
1023 /*
1024  * Copyright (c) 2004-2007 by Dinkumware, Ltd.  ALL RIGHTS RESERVED.
1025  * Consult your license regarding permissions and restrictions.
1026 V5.03:0009 */
1027