ZFFramework
 
Loading...
Searching...
No Matches
zfstlhashmap.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfstlhashmap_h_
7#define _ZFI_zfstlhashmap_h_
8
9#include "zfstlpair.h"
10
11// ============================================================
13#ifndef zfstlhashmap
14 #define zfstlhashmap std::unordered_map
15 #include "zfstl_impl/unordered_map.hpp"
16#endif
17
19#ifndef zfstlhash
20 #ifdef _ZFT_zfstlhash
21 #define zfstlhash _ZFT_zfstlhash
22 #else
23 #define zfstlhash std::hash
24 #endif
25#endif
26
28#ifndef zfstlequalto
29 #ifdef _ZFT_zfstlequalto
30 #define zfstlequalto _ZFT_zfstlequalto
31 #else
32 #define zfstlequalto std::equal_to
33 #endif
34#endif
35
36
37// ============================================================
39template<typename T_Key, typename T_Value, typename T_Hash = zfstlhash<T_Key>, typename T_Equal = zfstlequalto<T_Key> >
40class zfimplhashmap : public zfstlhashmap<T_Key, T_Value, T_Hash, T_Equal> {
41private:
43 public:
44 typename zfimplhashmap<T_Key, T_Value, T_Hash, T_Equal>::iterator it;
45 typename zfimplhashmap<T_Key, T_Value, T_Hash, T_Equal>::iterator end;
46 public:
48 virtual zfbool valid(void) {
49 return it != end;
50 }
52 virtual void next(void) {
53 ++it;
54 }
56 virtual Impl *copy(void) {
57 _Iter *ret = zfpoolNew(_Iter);
58 ret->it = it;
59 ret->end = end;
60 return ret;
61 }
63 virtual void destroy(void) {
64 zfpoolDelete(this);
65 }
67 virtual zfbool isEqual(ZF_IN Impl *d) {
68 _Iter *t = (_Iter *)d;
69 return it == t->it;
70 }
71 };
72public:
73 zffinal inline zfiter iter(void) {
74 _Iter *impl = zfpoolNew(_Iter);
75 impl->it = this->begin();
76 impl->end = this->end();
77 return zfiter(impl);
78 }
79
80 zffinal inline zfiter iterFind(ZF_IN T_Key const &key) {
81 _Iter *impl = zfpoolNew(_Iter);
82 impl->it = this->find(key);
83 impl->end = this->end();
84 return zfiter(impl);
85 }
86
87 zffinal inline T_Key const &iterKey(ZF_IN const zfiter &it) {
88 return it.impl<_Iter *>()->it->first;
89 }
90 zffinal inline T_Value &iterValue(ZF_IN const zfiter &it) {
91 return it.impl<_Iter *>()->it->second;
92 }
93
94 zffinal inline void iterValue(
96 , ZF_IN T_Value const &newValue
97 ) {
98 it.impl<_Iter *>()->it->second = newValue;
99 }
100 zffinal inline void iterRemove(ZF_IN_OUT zfiter &it) {
101 this->erase((it.impl<_Iter *>()->it)++);
102 }
103
104 zffinal inline void iterAdd(
105 ZF_IN T_Key const &key
106 , ZF_IN T_Value const &value
107 ) {
108 this->insert(zfstlpair<T_Key, T_Value>(key, value));
109 }
110};
112
113// ============================================================
115template<typename T_Type>
117public:
118 zfstlsize operator () (T_Type const &v) const {
119 return (zfstlsize)zfhash(v);
120 }
121};
122
123// ============================================================
125template<>
127public:
128 zfstlsize operator () (zffloat const &v) const {
129 return (zfstlsize)zfidentityCalc(v);
130 }
131};
132template<>
134public:
135 zfstlsize operator () (zfdouble const &v) const {
136 return (zfstlsize)zfidentityCalc(v);
137 }
138};
139template<>
141public:
142 zfstlsize operator () (zftimet const &v) const {
143 return (zfstlsize)zfidentityCalc(v);
144 }
145};
146template<>
148public:
149 zfstlsize operator () (zfflags const &v) const {
150 return (zfstlsize)zfidentityCalc(v);
151 }
152};
153template<>
155public:
156 zfstlsize operator () (zfidentity const &v) const {
157 return (zfstlsize)zfidentityCalc(v);
158 }
159};
160template<>
162public:
163 zfstlsize operator () (ZFIndexRange const &v) const {
164 return (zfstlsize)zfidentityCalc(v);
165 }
166};
167template<>
169public:
170 zfstlsize operator () (zfstring const &v) const {
172 }
173};
174template<>
176public:
177 zfstlsize operator () (ZFSigName const &v) const {
179 }
180};
182
183#endif // #ifndef _ZFI_zfstlhashmap_h_
184
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_zft_zfflags zfflags
used to hold flags, ensured 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:211
_zft_zftimet zftimet
time unit, ensured at least 64 bit, ensured signed
Definition ZFCoreTypeDef_CoreType.h:203
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
_zft_zffloat zffloat
same as float, see zfindex
Definition ZFCoreTypeDef_CoreType.h:183
_zft_zfdouble zfdouble
same as double, see zfindex
Definition ZFCoreTypeDef_CoreType.h:188
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
zfidentity zfhash(const T_Type &v)
std::hash wrapper
Definition ZFCoreUtilTemplate.h:516
zfidentity zfidentityCalc(T_Type const &v)
calculate identity from POD object
Definition ZFIdentityUtil.h:92
zfidentity zfidentityCalcString(const zfchar *src, zfindex srcLen=((zfindex) -1))
calculate identity from string
#define zfpoolDelete(obj)
see zfpoolNew
Definition ZFMemPool.h:38
#define zfpoolNew(T_Type,...)
internal use only, for allocating internal types for performance
Definition ZFMemPool.h:37
POD data to hold index range.
Definition ZFCoreTypeDef_OtherType.h:66
readonly string container for internal use only
Definition ZFSigName.h:17
const zfchar * cString(void) const
access string value, return empty string if empty
zfindex length(void) const
length of string content
see zfiter
Definition zfiter.h:84
iterator for ZFFramework
Definition zfiter.h:40
hash wrapper for zftHash
Definition zfstlhashmap.h:116
const T_Char * cString(void) const
access string value
Definition zfstring.h:464
zfindex length(void) const
length of the string
Definition zfstring.h:468
#define zfstlsize
size_t wrapper
Definition zfstl_define.h:29
#define zfstlhash
stl wrapper
Definition zfstlhashmap.h:23
#define zfstlhashmap
stl wrapper
Definition zfstlhashmap.h:14
stl wrapper, note it's internal use only
#define zfstlpair
stl wrapper
Definition zfstlpair.h:15