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 #ifndef REGION_MAP_INCLUDED
00078 #define REGION_MAP_INCLUDED
00079
00080 #include "region.h"
00081
00082
00083 #define REGION_map_idx(region) region->Id()
00084
00085
00086 typedef enum {
00087 _REGION_MAP_PTR,
00088 _REGION_MAP_I32,
00089 _REGION_MAP_I64
00090 } _REGION_MAP_KIND;
00091
00092
00093 typedef struct region_map {
00094 mUINT32 length;
00095 mUINT32 gen;
00096 mUINT32 *value_gens;
00097 union {
00098 void **ptr;
00099 mINT32 *i32;
00100 mINT64 *i64;
00101 } values;
00102 _REGION_MAP_KIND kind;
00103 mBOOL deleted;
00104 } *REGION_MAP;
00105
00106
00107 void REGION_MAP_Init(void);
00108
00109 REGION_MAP REGION_MAP_create_kind(INT32 REGION_MAP_idx_max, _REGION_MAP_KIND kind);
00110
00111 void REGION_MAP_Delete(REGION_MAP map);
00112
00113 void REGION_MAP_grow(REGION_MAP map, REGION *region);
00114
00115
00116 inline void REGION_MAP_Set(REGION_MAP map, REGION *region, void *value)
00117 {
00118 UINT32 idx = REGION_map_idx(region);
00119 DevAssert(map->kind == _REGION_MAP_PTR, ("REGION_MAP has wrong kind"));
00120 if (value && idx >= map->length)
00121 REGION_MAP_grow(map, region);
00122 if (idx < map->length) {
00123 map->values.ptr[idx] = value;
00124 map->value_gens[idx] = map->gen;
00125 }
00126 }
00127
00128
00129 inline void REGION_MAP32_Set(REGION_MAP map, REGION *region, INT32 value)
00130 {
00131 UINT32 idx = REGION_map_idx(region);
00132 DevAssert(map->kind == _REGION_MAP_I32, ("REGION_MAP has wrong kind"));
00133 if (value && idx >= map->length)
00134 REGION_MAP_grow(map, region);
00135 if (idx < map->length) {
00136 map->values.i32[idx] = value;
00137 map->value_gens[idx] = map->gen;
00138 }
00139 }
00140
00141
00142 inline void REGION_MAP64_Set(REGION_MAP map, REGION *region, INT64 value)
00143 {
00144 UINT32 idx = REGION_map_idx(region);
00145 DevAssert(map->kind == _REGION_MAP_I64, ("REGION_MAP has wrong kind"));
00146 if (value && idx >= map->length)
00147 REGION_MAP_grow(map, region);
00148 if (idx < map->length) {
00149 map->values.i64[idx] = value;
00150 map->value_gens[idx] = map->gen;
00151 }
00152 }
00153
00154
00155 inline void *REGION_MAP_Get(REGION_MAP map, REGION *region)
00156 {
00157 UINT32 idx = REGION_map_idx(region);
00158 DevAssert(map->kind == _REGION_MAP_PTR, ("REGION_MAP has wrong kind"));
00159 return idx < map->length && map->value_gens[idx] == map->gen ?
00160 map->values.ptr[idx] : NULL;
00161 }
00162
00163
00164 inline INT32 REGION_MAP32_Get(REGION_MAP map, REGION *region)
00165 {
00166 UINT32 idx = REGION_map_idx(region);
00167 DevAssert(map->kind == _REGION_MAP_I32, ("REGION_MAP has wrong kind"));
00168 return idx < map->length && map->value_gens[idx] == map->gen ?
00169 map->values.i32[idx] : 0;
00170 }
00171
00172
00173 inline INT64 REGION_MAP64_Get(REGION_MAP map, REGION *region)
00174 {
00175 UINT64 idx = REGION_map_idx(region);
00176 DevAssert(map->kind == _REGION_MAP_I64, ("REGION_MAP has wrong kind"));
00177 return idx < map->length && map->value_gens[idx] == map->gen ?
00178 map->values.i64[idx] : 0;
00179 }
00180
00181
00182 #define REGION_MAP_Create(size) REGION_MAP_create_kind(size, _REGION_MAP_PTR)
00183
00184 #define REGION_MAP32_Create() REGION_MAP_create_kind(_REGION_MAP_I32)
00185
00186 #define REGION_MAP64_Create() REGION_MAP_create_kind(_REGION_MAP_I64)
00187
00188 #endif