Reformatted some comments and rearranged things within the RocDict def

This commit is contained in:
Chadtech 2021-01-03 13:17:03 -05:00
parent 12d836bfb0
commit d3b569f6eb

View file

@ -18,6 +18,9 @@ pub fn RocDict(
return struct { return struct {
const Self = @This(); const Self = @This();
len: u64,
entries: [size]?Entry,
pub const Entry = struct { pub const Entry = struct {
key_ptr: *Key, key_ptr: *Key,
value_ptr: *Value, value_ptr: *Value,
@ -26,14 +29,9 @@ pub fn RocDict(
pub const Overflow = struct { pub const Overflow = struct {
entries: *[size]?*Entry, entries: *[size]?*Entry,
// This function takes an // This function takes an index, key, and value, because presumably overflow
// index, key, and value, // is only created once an there is a collision between two entries, and
// because presumably overflow // there is therefore an extra entry that needs to be stored
// is only created once an
// there is a collision between
// two entries, and there is
// therefore an extra entry
// that needs to be stored
pub fn new(allocator: *Allocator, index: u64, key_ptr: *Key, value_ptr: *Value) Overflow { pub fn new(allocator: *Allocator, index: u64, key_ptr: *Key, value_ptr: *Value) Overflow {
var init_entries: [size]?*Entry = undefined; var init_entries: [size]?*Entry = undefined;
@ -105,10 +103,8 @@ pub fn RocDict(
} }
} }
// The bool this function returns // The bool this function returns represents if an new entry was
// represents if an new entry was // added (true), or if an old one was updated (false);
// added (true), or if an old one
// was updated (false);
pub fn insertIntoOverflow(self: *Entry, allocator: *Allocator, key_ptr: *Key, value_ptr: *Value, level: u64) bool { pub fn insertIntoOverflow(self: *Entry, allocator: *Allocator, key_ptr: *Key, value_ptr: *Value, level: u64) bool {
const key = key_ptr.*; const key = key_ptr.*;
@ -157,9 +153,6 @@ pub fn RocDict(
maybe_entry: ?Entry maybe_entry: ?Entry
}; };
len: u64,
entries: [size]?Entry,
fn query(self: Self, key: Key, level: u64) Query { fn query(self: Self, key: Key, level: u64) Query {
const index = keyToIndexAtLevel(key, level); const index = keyToIndexAtLevel(key, level);