Compare commits

..

No commits in common. "62f5d8394be3efda59807d47c08deec55d2032ae" and "1b6d48d14bb87be48279544f959510a11790edad" have entirely different histories.

3 changed files with 7 additions and 116 deletions

View file

@ -25,18 +25,6 @@ resize :: inline (arr: *[..]$T, new_size: int) {
basic.array_reserve(arr, new_size,, allocator = arr.allocator);
}
remove_ordered :: inline (arr: *[..]$T, index: int, loc := #caller_location) #no_abc {
meta.check_bounds(index, arr.count, loc = loc);
memcpy(arr.data + index, arr.data + index + 1, (arr.count - index - 1) * size_of(T));
arr.count -= 1;
}
remove_unordered :: inline (arr: *[..]$T, index: int, loc := #caller_location) #no_abc {
meta.check_bounds(index, arr.count, loc = loc);
arr.data[index] = arr.data[arr.count - 1];
arr.count -= 1;
}
reset :: inline (arr: *[..]$T) {
arr.count = 0;
}
@ -52,51 +40,6 @@ find_pointer :: (a: *[..]$T, $predicate: (T) -> bool) -> *T, bool, int {
}
#scope_file;
mem :: #import "jc/memory";
meta :: #import "jc/meta";
basic :: #import "Basic"; // @future
#if RUN_TESTS #run {
test.run("remove_ordered", t => {
a: [..]int;
append(*a, 10, 20, 30);
remove_ordered(*a, 1);
test.expect(t, a.count == 2);
test.expect(t, a.data[0] == 10);
test.expect(t, a.data[1] == 30);
remove_ordered(*a, 0);
test.expect(t, a.count == 1);
test.expect(t, a.data[0] == 30);
remove_ordered(*a, 0);
test.expect(t, a.count == 0);
append(*a, 10);
test.expect(t, a.count == 1);
test.expect(t, a.data[0] == 10);
});
test.run("remove_unordered", t => {
a: [..]int;
append(*a, 10, 20, 30);
remove_unordered(*a, 1);
test.expect(t, a.count == 2);
test.expect(t, a.data[0] == 10);
test.expect(t, a.data[1] == 30);
remove_unordered(*a, 0);
test.expect(t, a.count == 1);
test.expect(t, a.data[0] == 30);
remove_unordered(*a, 0);
test.expect(t, a.count == 0);
append(*a, 10);
test.expect(t, a.count == 1);
test.expect(t, a.data[0] == 10);
});
}

View file

@ -28,18 +28,6 @@ append :: inline (a: *Static_Array, items: ..a.T) -> *a.T #no_abc {
return first;
}
remove_ordered :: inline (a: *Static_Array, index: int, loc := #caller_location) #no_abc {
meta.check_bounds(index, a.count, loc = loc);
memcpy(a.items.data + index, a.items.data + index + 1, (a.count - index - 1) * size_of(a.T));
a.count -= 1;
}
remove_unordered :: inline (a: *Static_Array, index: int, loc := #caller_location) #no_abc {
meta.check_bounds(index, a.count, loc = loc);
a.items[index] = a.items[a.count - 1];
a.count -= 1;
}
reset :: inline (a: *Static_Array) #no_abc {
for 0..a.count - 1 a.items[it] = a.Default;
a.count = 0;
@ -126,44 +114,4 @@ basic :: #import "Basic"; // @future
_, ok = find_pointer(*a, v => v == 20);
test.expect(t, ok);
});
test.run("remove_ordered", (t) => {
a: Static_Array(10, int);
append(*a, 10, 20, 30);
remove_ordered(*a, 1);
test.expect(t, a.count == 2);
test.expect(t, a.items[0] == 10);
remove_ordered(*a, 0);
test.expect(t, a.count == 1);
test.expect(t, a.items[0] == 30);
remove_ordered(*a, 0);
test.expect(t, a.count == 0);
append(*a, 10);
test.expect(t, a.count == 1);
test.expect(t, a.items[0] == 10);
});
test.run("remove_unordered", (t) => {
a: Static_Array(10, int);
append(*a, 10, 20, 30);
remove_unordered(*a, 1);
test.expect(t, a.count == 2);
test.expect(t, a.items[1] == 30);
remove_unordered(*a, 0);
test.expect(t, a.count == 1);
test.expect(t, a.items[0] == 30);
remove_unordered(*a, 0);
test.expect(t, a.count == 0);
append(*a, 10);
test.expect(t, a.count == 1);
test.expect(t, a.items[0] == 10);
});
}

View file

@ -45,8 +45,8 @@ set :: (kv: *Kv, key: kv.Key, value: kv.Value) {
slot.value = value;
}
// @note(judah): we use 'delete' instead of 'remove' because it's a keyword...
delete :: (kv: *Kv, key: kv.Key) -> kv.Value, bool {
// @note(judah): we use 'evict' instead of 'remove' because it's a keyword...
evict :: (kv: *Kv, key: kv.Key) -> kv.Value, bool {
slot, ok, idx := find_slot(kv, kv.hash_proc(key));
if !ok return mem.zero_of(kv.Value), false;
@ -145,7 +145,7 @@ hash :: #import "jc/hash";
}
for 0..ITERATIONS if it % 2 == 0 {
_, ok := delete(*values, it);
_, ok := evict(*values, it);
test.expect(t, ok);
}
@ -164,12 +164,12 @@ hash :: #import "jc/hash";
test.expect(t, values.count == 3);
test.expect(t, values.slots.allocated == values.number_of_items_to_allocate_initially);
// deleting something that doesn't exist should do nothing
_, ok := delete(*values, 0);
// evicting something that doesn't exist should do nothing
_, ok := evict(*values, 0);
test.expect(t, !ok);
test.expect(t, values.count == 3);
delete(*values, 2);
evict(*values, 2);
test.expect(t, values.count == 2);
});