00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #ifndef BB_MAP_INCLUDED
00086 #define BB_MAP_INCLUDED
00087
00088 #include "bb.h"
00089
00090
00091
00092 #define BB_MAP_idx_max PU_BB_Count
00093 #define BB_map_idx(bb) BB_id(bb)
00094
00095
00096 typedef enum {
00097 _BB_MAP_PTR,
00098 _BB_MAP_I32,
00099 _BB_MAP_I64
00100 } _BB_MAP_KIND;
00101
00102
00103 typedef struct bb_map {
00104 mUINT32 length;
00105 mUINT32 gen;
00106 mUINT32 *value_gens;
00107 union {
00108 void **ptr;
00109 mINT32 *i32;
00110 mINT64 *i64;
00111 } values;
00112 _BB_MAP_KIND kind;
00113 mBOOL deleted;
00114 } *BB_MAP;
00115
00116
00117 void BB_MAP_Init(void);
00118
00119 BB_MAP BB_MAP_create_kind(_BB_MAP_KIND kind);
00120
00121 void BB_MAP_Delete(BB_MAP map);
00122
00123 void BB_MAP_grow(BB_MAP map, BB *bb);
00124
00125
00126 inline void BB_MAP_Set(BB_MAP map, BB *bb, void *value)
00127 {
00128 UINT32 idx = BB_map_idx(bb);
00129 DevAssert(map->kind == _BB_MAP_PTR, ("BB_MAP has wrong kind"));
00130 if (value && idx >= map->length)
00131 BB_MAP_grow(map, bb);
00132 if (idx < map->length) {
00133 map->values.ptr[idx] = value;
00134 map->value_gens[idx] = map->gen;
00135 }
00136 }
00137
00138
00139 inline void BB_MAP32_Set(BB_MAP map, BB *bb, INT32 value)
00140 {
00141 UINT32 idx = BB_map_idx(bb);
00142 DevAssert(map->kind == _BB_MAP_I32, ("BB_MAP has wrong kind"));
00143 if (value && idx >= map->length)
00144 BB_MAP_grow(map, bb);
00145 if (idx < map->length) {
00146 map->values.i32[idx] = value;
00147 map->value_gens[idx] = map->gen;
00148 }
00149 }
00150
00151
00152 inline void BB_MAP64_Set(BB_MAP map, BB *bb, INT64 value)
00153 {
00154 UINT32 idx = BB_map_idx(bb);
00155 DevAssert(map->kind == _BB_MAP_I64, ("BB_MAP has wrong kind"));
00156 if (value && idx >= map->length)
00157 BB_MAP_grow(map, bb);
00158 if (idx < map->length) {
00159 map->values.i64[idx] = value;
00160 map->value_gens[idx] = map->gen;
00161 }
00162 }
00163
00164
00165 inline void *BB_MAP_Get(BB_MAP map, BB *bb)
00166 {
00167 UINT32 idx = BB_map_idx(bb);
00168 DevAssert(map->kind == _BB_MAP_PTR, ("BB_MAP has wrong kind"));
00169 return idx < map->length && map->value_gens[idx] == map->gen ?
00170 map->values.ptr[idx] : NULL;
00171 }
00172
00173
00174 inline INT32 BB_MAP32_Get(BB_MAP map, BB *bb)
00175 {
00176 UINT32 idx = BB_map_idx(bb);
00177 DevAssert(map->kind == _BB_MAP_I32, ("BB_MAP has wrong kind"));
00178 return idx < map->length && map->value_gens[idx] == map->gen ?
00179 map->values.i32[idx] : 0;
00180 }
00181
00182
00183 inline INT64 BB_MAP64_Get(BB_MAP map, BB *bb)
00184 {
00185 UINT64 idx = BB_map_idx(bb);
00186 DevAssert(map->kind == _BB_MAP_I64, ("BB_MAP has wrong kind"));
00187 return idx < map->length && map->value_gens[idx] == map->gen ?
00188 map->values.i64[idx] : 0;
00189 }
00190
00191
00192 #define BB_MAP_Create() BB_MAP_create_kind(_BB_MAP_PTR)
00193
00194 #define BB_MAP32_Create() BB_MAP_create_kind(_BB_MAP_I32)
00195
00196 #define BB_MAP64_Create() BB_MAP_create_kind(_BB_MAP_I64)
00197
00198 #endif