MapPolicy
Description
Probing / rehash policy currently installed on m. The returned MapPolicy value is borrowed from inside the map – read-only.
Parameters
| Name | Direction | Description |
|---|---|---|
m |
in | Map. |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Map.c:88:
}
void validate_map_policy(const MapPolicy *policy) {
static const struct {
u64 length;- In
Map.c:104:
if (!policy) {
LOG_FATAL("Expected a valid MapPolicy pointer");
}- In
Map.c:108:
if (!policy->name || !policy->name[0]) {
LOG_FATAL("MapPolicy must have a non-empty name");
}- In
Map.c:112:
if (!policy->should_rehash || !policy->next_capacity || !policy->first_index || !policy->next_index) {
LOG_FATAL("MapPolicy '{}' must provide all required callbacks", policy->name);
}- In
Map.c:116:
if (policy->max_probe_count == 0) {
LOG_FATAL("MapPolicy '{}' must provide a non-zero max_probe_count", policy->name);
}- In
Map.c:130:
if ((next0 == 0) && ((length != 0) || (capacity != 0) || (tombstones != 0))) {
LOG_FATAL("MapPolicy '{}' returned zero capacity for a non-empty snapshot", policy->name);
}- In
Map.c:134:
if ((next_same != 0) && (next_same < length)) {
LOG_FATAL("MapPolicy '{}' returned capacity smaller than current length", policy->name);
}- In
Map.c:138:
if (next_more < ((size)length + 1)) {
LOG_FATAL("MapPolicy '{}' returned capacity smaller than requested minimum entries", policy->name);
}
}- In
Map.c:151:
if (next == first) {
LOG_FATAL("MapPolicy '{}' produced a stuck probe sequence for capacity {}", policy->name, capacity);
}
}- In
Map.c:157:
}
MapPolicy validate_map_policy_copy(MapPolicy policy) {
validate_map_policy(&policy);
return policy;- In
Map.c:162:
}
const MapPolicy MapPolicyLinear = {
.name = "linear",
.should_rehash = default_should_rehash,- In
Map.c:171:
};
const MapPolicy MapPolicyQuadratic = {
.name = "quadratic",
.should_rehash = default_should_rehash,- In
Map.c:498:
size hash_offset,
size n,
MapPolicy policy
) {
u8 *old_entries; WriteFmt("Testing ValidateMapPolicy without name\n");
MapPolicy policy = {
.name = "",
.should_rehash = always_rehash, WriteFmt("Testing ValidateMapPolicy without probe limit\n");
MapPolicy policy = {
.name = "invalid",
.should_rehash = always_rehash,- In
Map.Init.c:91:
MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&- In
Map.Init.c:92:
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&
(MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);- In
Map.Init.c:93:
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&
(MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);- In
Map.Init.c:94:
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&
(MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);
for (int i = 0; i < 24; i++) {- In
Map.Init.c:109:
typedef Map(int, int) IntIntMap;
DefaultAllocator alloc = DefaultAllocatorInit();
MapPolicy custom_policy = {
.name = "five-step",
.should_rehash = custom_should_rehash,- In
Map.Init.c:125:
result = result && (MapCapacity(&map) == 10);
result = result && (MapPolicy(&map).next_capacity == custom_next_capacity);
for (int i = 0; i < 6; i++) {- In
Map.Ops.c:91:
MapRehashWithPolicy(&map, MapPairCount(&map), MapPolicyQuadratic);
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&- In
Map.Ops.c:92:
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&
(MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);- In
Map.Ops.c:93:
bool result = (MapPolicy(&map).first_index == MapPolicyQuadratic.first_index) &&
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&
(MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);
result = result && (MapValueCountForKey(&map, "red") == 2);- In
Map.Ops.c:94:
(MapPolicy(&map).next_index == MapPolicyQuadratic.next_index) &&
(MapPolicy(&map).next_capacity == MapPolicyQuadratic.next_capacity) &&
(MapPolicy(&map).should_rehash == MapPolicyQuadratic.should_rehash);
result = result && (MapValueCountForKey(&map, "red") == 2);
result = result && MapGetFirstPtr(&map, "red") && (ZstrCompare(*MapGetFirstPtr(&map, "red"), "apple") == 0);- In
Map.Type.c:63:
MapEntries(&map) == NULL && MapStates(&map) == NULL && MapKeyCompare(&map) == i32_compare &&
MapValueCompare(&map) == NULL && MapKeyHash(&map) == i32_hash &&
MapPolicy(&map).should_rehash == MapPolicyLinear.should_rehash &&
MapPolicy(&map).next_capacity == MapPolicyLinear.next_capacity &&
MapPolicy(&map).first_index == MapPolicyLinear.first_index &&- In
Map.Type.c:64:
MapValueCompare(&map) == NULL && MapKeyHash(&map) == i32_hash &&
MapPolicy(&map).should_rehash == MapPolicyLinear.should_rehash &&
MapPolicy(&map).next_capacity == MapPolicyLinear.next_capacity &&
MapPolicy(&map).first_index == MapPolicyLinear.first_index &&
MapPolicy(&map).next_index == MapPolicyLinear.next_index &&- In
Map.Type.c:65:
MapPolicy(&map).should_rehash == MapPolicyLinear.should_rehash &&
MapPolicy(&map).next_capacity == MapPolicyLinear.next_capacity &&
MapPolicy(&map).first_index == MapPolicyLinear.first_index &&
MapPolicy(&map).next_index == MapPolicyLinear.next_index &&
MapPolicy(&map).max_probe_count == MapPolicyLinear.max_probe_count;- In
Map.Type.c:66:
MapPolicy(&map).next_capacity == MapPolicyLinear.next_capacity &&
MapPolicy(&map).first_index == MapPolicyLinear.first_index &&
MapPolicy(&map).next_index == MapPolicyLinear.next_index &&
MapPolicy(&map).max_probe_count == MapPolicyLinear.max_probe_count;- In
Map.Type.c:67:
MapPolicy(&map).first_index == MapPolicyLinear.first_index &&
MapPolicy(&map).next_index == MapPolicyLinear.next_index &&
MapPolicy(&map).max_probe_count == MapPolicyLinear.max_probe_count;
MapDeinit(&map);- In
Map.Type.c:90:
typedef Map(int, int) IntIntMap;
DefaultAllocator alloc = DefaultAllocatorInit();
MapPolicy custom_policy = {
.name = "custom-linear",
.should_rehash = custom_should_rehash_snapshot,- In
Map.Type.c:107:
custom_policy.max_probe_count = 0;
bool result = ZstrCompare(MapPolicy(&map).name, "custom-linear") == 0 &&
MapPolicy(&map).should_rehash == custom_should_rehash_snapshot &&
MapPolicy(&map).next_capacity == custom_next_capacity &&- In
Map.Type.c:108:
bool result = ZstrCompare(MapPolicy(&map).name, "custom-linear") == 0 &&
MapPolicy(&map).should_rehash == custom_should_rehash_snapshot &&
MapPolicy(&map).next_capacity == custom_next_capacity &&
MapPolicy(&map).first_index == custom_first_index &&- In
Map.Type.c:109:
bool result = ZstrCompare(MapPolicy(&map).name, "custom-linear") == 0 &&
MapPolicy(&map).should_rehash == custom_should_rehash_snapshot &&
MapPolicy(&map).next_capacity == custom_next_capacity &&
MapPolicy(&map).first_index == custom_first_index &&
MapPolicy(&map).next_index == custom_next_index && MapPolicy(&map).max_probe_count == 11;- In
Map.Type.c:110:
MapPolicy(&map).should_rehash == custom_should_rehash_snapshot &&
MapPolicy(&map).next_capacity == custom_next_capacity &&
MapPolicy(&map).first_index == custom_first_index &&
MapPolicy(&map).next_index == custom_next_index && MapPolicy(&map).max_probe_count == 11;- In
Map.Type.c:111:
MapPolicy(&map).next_capacity == custom_next_capacity &&
MapPolicy(&map).first_index == custom_first_index &&
MapPolicy(&map).next_index == custom_next_index && MapPolicy(&map).max_probe_count == 11;
MapDeinit(&map);- In
Map.Type.c:119:
static bool test_validate_map_policy(void) {
MapPolicy custom_policy = {
.name = "custom-linear",
.should_rehash = custom_should_rehash_snapshot,- In
Type.h:80:
MapPolicyNextIndexFn next_index;
size max_probe_count;
} MapPolicy;
///
- In
Type.h:89:
/// TAGS: Map, Constant, Policy
///
extern const MapPolicy MapPolicyLinear;
///
- In
Type.h:98:
/// TAGS: Map, Constant, Policy
///
extern const MapPolicy MapPolicyQuadratic;
typedef struct {- In
Type.h:117:
u8 *entries;
u8 *states;
MapPolicy policy;
Allocator *allocator;
u64 __magic;- In
Type.h:183:
MapEntry(K, V) * entries; \
u8 *states; \
MapPolicy policy; \
Allocator *allocator; \
u64 __magic; \
Last updated on