Entry :: struct (K: type_expr, V: type_expr) {
next : i32;
+ hash : u32;
key : K;
value : V;
}
return;
}
- entries << .{ hashes[lr.hash_index], key, value };
+ entries << .{ hashes[lr.hash_index], lr.hash, key, value };
hashes[lr.hash_index] = entries.count - 1;
if full(map) do grow(map);
hash_index : i32 = -1;
entry_index : i32 = -1;
entry_prev : i32 = -1;
+ hash : u32 = 0;
}
lookup :: (use map: ^Map, key: map.Key_Type) -> MapLookupResult {
lr := MapLookupResult.{};
hash_value: u32 = hash.to_u32(key); // You cannot use this type for the key, unless you add an overload.
+ lr.hash = hash_value;
lr.hash_index = hash_value % hashes.count;
lr.entry_index = hashes[lr.hash_index];
while lr.entry_index >= 0 {
- if entries[lr.entry_index].key == key do return lr;
+ if entries[lr.entry_index].hash == hash_value {
+ if entries[lr.entry_index].key == key do return lr;
+ }
lr.entry_prev = lr.entry_index;
lr.entry_index = entries[lr.entry_index].next;
Entry :: struct (T: type_expr) {
next : i32;
+ hash : u32;
value : T;
}
if lr.entry_index >= 0 do return;
- entries << .{ hashes[lr.hash_index], value };
+ entries << .{ hashes[lr.hash_index], lr.hash, value };
hashes[lr.hash_index] = entries.count - 1;
if full(set) do grow(set);
hash_index : i32 = -1;
entry_index : i32 = -1;
entry_prev : i32 = -1;
+ hash : u32 = 0;
}
lookup :: (use set: ^Set, value: set.Elem_Type) -> SetLookupResult {
lr := SetLookupResult.{};
hash_value: u32 = hash.to_u32(value); // You cannot have a set of this type without defining a to_u32 hash.
+ lr.hash = hash_value;
lr.hash_index = hash_value % hashes.count;
lr.entry_index = hashes[lr.hash_index];
while lr.entry_index >= 0 {
- if entries[lr.entry_index].value == value do return lr;
+ if entries[lr.entry_index].hash == hash_value {
+ if entries[lr.entry_index].value == value do return lr;
+ }
lr.entry_prev = lr.entry_index;
lr.entry_index = entries[lr.entry_index].next;
curr_pos : i32;
data : [..] u8;
+
+ to_str :: dynamic_string_stream_to_str;
}
dynamic_string_stream_make :: (init_size := 128, a := context.allocator) -> DynamicStringStream {
return Writer.{ s };
}
+//
+// Future-proofing the API
+writer_free :: (w: ^Writer) {}
+
string_builder :: (allocator := context.allocator) -> (Writer, ^DynamicStringStream) {
new_stream := new(DynamicStringStream, allocator=allocator);
*new_stream = dynamic_string_stream_make();
r: io.Reader;
w: io.Writer;
+ close :: (this: ^Connection) {
+ this.socket->close();
+ io.reader_free(^this.r);
+ io.writer_free(^this.w);
+ }
+
get :: (this: ^Connection, resource: str, params: [] Key_Value_Pair, headers: [] Key_Value_Pair = .[]) -> Response {
req := Request.get(resource, params, headers);
return send_request(this, ^req);
[
Map.Entry([] u8, i32) {
next = -1,
+ hash = 193461347,
key = "Joe",
value = 12
},
Map.Entry([] u8, i32) {
next = 0,
+ hash = 2089242307,
key = "Jane",
value = 34
}