rename generational_array_list to slot_map
This commit is contained in:
parent
b901c474f0
commit
9becd7d56b
@ -255,7 +255,7 @@ const SokolSetupOptions = struct {
|
||||
buffer_frames: u32
|
||||
};
|
||||
|
||||
const SoundList = Lib.GenerationalArrayList(u8, u8, Sound);
|
||||
const SoundList = Lib.SlotMap(u8, u8, Sound);
|
||||
comptime {
|
||||
assert(@bitSizeOf(SoundList.Id) == @bitSizeOf(Lib.Sound.Id));
|
||||
}
|
||||
|
||||
@ -77,13 +77,13 @@ const Font = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const FontArray = Lib.GenerationalArrayList(u8, u8, Font);
|
||||
const FontArray = Lib.SlotMap(u8, u8, Font);
|
||||
comptime {
|
||||
assert(@bitSizeOf(FontArray.Id) == @bitSizeOf(Lib.Font.Id));
|
||||
assert(FontArray.Id.none.asInt() == @intFromEnum(Lib.Font.Id.nil));
|
||||
}
|
||||
|
||||
const TexturesArray = Lib.GenerationalArrayList(u8, u8, Texture);
|
||||
const TexturesArray = Lib.SlotMap(u8, u8, Texture);
|
||||
comptime {
|
||||
// TODO: This is PITA, can this be refactored?
|
||||
assert(@bitSizeOf(TexturesArray.Id) == @bitSizeOf(Lib.Texture.Id));
|
||||
|
||||
@ -4,7 +4,7 @@ const log = std.log.scoped(.engine);
|
||||
pub const build_options = @import("build_options");
|
||||
pub const ImGui = @import("./imgui.zig");
|
||||
pub const Math = @import("./math.zig");
|
||||
pub const GenerationalArrayList = @import("./generational_array_list.zig").GenerationalArrayList;
|
||||
pub const SlotMap = @import("./slot_map.zig").SlotMap;
|
||||
const STBImage = @import("stb_image");
|
||||
|
||||
const rgb = Math.rgb;
|
||||
|
||||
@ -9,7 +9,7 @@ const Allocator = std.mem.Allocator;
|
||||
/// - Unique IDs for every inserted item (assuming that generation doesn't overflow)
|
||||
/// TODO: Use a stack of unused indexes to implement O(1) insertion
|
||||
/// TODO: Implement a way to use a list *assumeCapacity() style of functions.
|
||||
pub fn GenerationalArrayList(
|
||||
pub fn SlotMap(
|
||||
Index: type,
|
||||
Generation: type,
|
||||
Item: type
|
||||
@ -368,13 +368,13 @@ pub fn GenerationalArrayList(
|
||||
};
|
||||
}
|
||||
|
||||
const TestArray = GenerationalArrayList(u24, u8, u32);
|
||||
const TestMap = SlotMap(u24, u8, u32);
|
||||
|
||||
test "insert & remove" {
|
||||
const expect = std.testing.expect;
|
||||
const gpa = std.testing.allocator;
|
||||
|
||||
var array_list: TestArray = .empty;
|
||||
var array_list: TestMap = .empty;
|
||||
defer array_list.deinit(gpa);
|
||||
|
||||
const id1 = try array_list.insert(gpa, 10);
|
||||
@ -393,7 +393,7 @@ test "generation wrap around" {
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const gpa = std.testing.allocator;
|
||||
|
||||
var array_list: TestArray = .empty;
|
||||
var array_list: TestMap = .empty;
|
||||
defer array_list.deinit(gpa);
|
||||
|
||||
// Grow array list so that at least 1 slot exists
|
||||
@ -401,7 +401,7 @@ test "generation wrap around" {
|
||||
array_list.removeAssumeExists(id1);
|
||||
|
||||
// Artificially increase generation count
|
||||
array_list.generations[id1.index] = std.math.maxInt(@FieldType(TestArray.Id, "generation"));
|
||||
array_list.generations[id1.index] = std.math.maxInt(@FieldType(TestMap.Id, "generation"));
|
||||
|
||||
// Check if generation wraps around
|
||||
const id2 = try array_list.insert(gpa, 10);
|
||||
@ -414,7 +414,7 @@ test "iterator" {
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const gpa = std.testing.allocator;
|
||||
|
||||
var array_list: TestArray = .empty;
|
||||
var array_list: TestMap = .empty;
|
||||
defer array_list.deinit(gpa);
|
||||
|
||||
// Create array which has a hole
|
||||
@ -426,14 +426,14 @@ test "iterator" {
|
||||
|
||||
var iter = array_list.iterator();
|
||||
try expectEqual(
|
||||
TestArray.ItemWithId{
|
||||
TestMap.ItemWithId{
|
||||
.id = id1,
|
||||
.item = array_list.getAssumeExists(id1)
|
||||
},
|
||||
iter.next().?
|
||||
);
|
||||
try expectEqual(
|
||||
TestArray.ItemWithId{
|
||||
TestMap.ItemWithId{
|
||||
.id = id3,
|
||||
.item = array_list.getAssumeExists(id3)
|
||||
},
|
||||
@ -446,10 +446,10 @@ test "read & write" {
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const gpa = std.testing.allocator;
|
||||
|
||||
var array_list1: TestArray = .empty;
|
||||
var array_list1: TestMap = .empty;
|
||||
defer array_list1.deinit(gpa);
|
||||
|
||||
var array_list2: TestArray = .empty;
|
||||
var array_list2: TestMap = .empty;
|
||||
defer array_list2.deinit(gpa);
|
||||
|
||||
const id1 = try array_list1.insert(gpa, 1);
|
||||
@ -475,7 +475,7 @@ test "clear retaining capacity" {
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const gpa = std.testing.allocator;
|
||||
|
||||
var array_list: TestArray = .empty;
|
||||
var array_list: TestMap = .empty;
|
||||
defer array_list.deinit(gpa);
|
||||
|
||||
const id1 = try array_list.insert(gpa, 10);
|
||||
Loading…
Reference in New Issue
Block a user