upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/45.md
diff options
context:
space:
mode:
Diffstat (limited to '45.md')
-rw-r--r--45.md15
1 files changed, 8 insertions, 7 deletions
diff --git a/45.md b/45.md
index 842d340..48ff447 100644
--- a/45.md
+++ b/45.md
@@ -41,13 +41,14 @@ This is so it enables merging results from multiple relays and yielding a reason
41 41
42### Algorithm 42### Algorithm
43 43
44The HLL value must be calculated with a precision of `8`, i.e. with 256 registers. 44This section describes the steps a relay should take in order to return HLL values to clients.
45 45
46To compute HLL values, first initi the 256 registers to `0` each; then, for on every event to be counted, 461. Upon receiving a filter, if it has a single `#e`, `#p`, `#a` or `#q` item, read its 32th ascii character as a byte and take its modulo over 24 to obtain an `offset` -- in the unlikely case that the filter doesn't meet these conditions, set `offset` to the number 16;
47 472. Initialize 256 registers to 0 for the HLL value;
48 1. take byte `16` of the `id` and use it to determine the register index; 483. For all the events that are to be counted according to the filter, do this:
49 2. count the number of leading zero bits in the following bytes `17..24` of the `id`; 49 1. Read byte at position `offset` of the event `pubkey`, its value will be the register index `ri`;
50 3. if the number of leading zeros is bigger than what was previously stored in that register, overwrite it. 50 2. Count the number of leading zero bits starting at position `offset+1` of the event `pubkey`;
51 3. Compare that with the value stored at register `ri`, if the new number is bigger, store it.
51 52
52That is all that has to be done on the relay side, and therefore the only part needed for interoperability. 53That is all that has to be done on the relay side, and therefore the only part needed for interoperability.
53 54