|
|
|
|
|
by seiflotfy
1255 days ago
|
|
This is awesome...
question though:
```pub fn HyperLogLog(comptime p: u8) type {
return struct {
dense: [1<<p]u6; const Self = @This();
pub fn init() Self {
var s = Self{};
for (s.dense) |*x| x.* = 0;
return s;
}
}
}```
doesn't this allocate 1<<p upfront though. If yes then the HLL of size 16384 bytes upfront which kinda beats the purpose of having a sparse representation no? |
|
Yes, it does. The idea (see the last code snipped in that post), is that the user delays the creation of the HLL until they are ready to switch to a dense representation. Before then, they just use a std.AutoHashMap directly.
Or, alternatively, the HLL could use the same buffer for both dense and sparse representation (see the Redis code).