You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Docs/Optimizations.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ But since there is just one element, we don't have to do all that. FastData will
12
12
This trick pertains to all types of lookup structures, but I'll use binary search as the example.
13
13
14
14
Binary search works by segmenting an array in half on each iteration of a lookup. It works on any input data, as long as we can establish a concept of `greater than`, `equal` and `less than` between elements.
15
-
However, if we can determine the input set is contiguous, then we don't need to do the binary search at all.
15
+
However, if we can determine the input set is consecutive, then we don't need to do the binary search at all.
16
16
17
17
Let's say the input is 42, 43, 44, 45.
18
18
- A check if 100 is in the list, is just `is 100 >= 45?`
@@ -27,6 +27,10 @@ Can we do better? Let's say you have an input like this: `house car fish`
27
27
In this case, each of the input strings have a unique length. So why not use their length as their hash? That's exactly what `KeyLengthStructure` does.
28
28
If the programming language cache the string length, we can get constant lookup time.
29
29
30
+
### Reduction to bitmap lookup
31
+
If a sequence of numbers is a short range, but cannot get optimized via the range reduction above, then it might be a good fit for a bitmap instead. Let's say you have the numbers in range 10-100 and 300-900.
32
+
Range reduction only works if the numbers are consecutive (until I add support for multi-ranges), and there are too many numbers to use conditionals efficiently, so instead we use a bitmap.
33
+
30
34
## Early exits
31
35
An early exit is a lightweight check we can perform before the actual lookup to speed up the process. They have to be **really** fast, otherwise they will add unwanted overhead to each call.
32
36
Only generalized data structures perform early exits, as reductions already have early exits built into them.
0 commit comments