All Projects → brentp → Nim Lapper

brentp / Nim Lapper

Licence: mit
fast easy interval overlapping for nim-lang

Programming Languages

nim
578 projects

Projects that are alternatives of or similar to Nim Lapper

Search cop
Search engine like fulltext query support for ActiveRecord
Stars: ✭ 660 (+2769.57%)
Mutual labels:  search
Dext
🔍 A smart launcher. Powered by JavaScript.
Stars: ✭ 713 (+3000%)
Mutual labels:  search
Javersphinxbundle
Symfony bundle which provides integration of Sphinx search engine with Symfony using SphinxQL
Stars: ✭ 18 (-21.74%)
Mutual labels:  search
Dsa.js Data Structures Algorithms Javascript
🥞Data Structures and Algorithms explained and implemented in JavaScript + eBook
Stars: ✭ 6,251 (+27078.26%)
Mutual labels:  search
Laravel Searchable
Pragmatically search through models and other sources
Stars: ✭ 701 (+2947.83%)
Mutual labels:  search
Ekanite
The Syslog server with built-in search
Stars: ✭ 729 (+3069.57%)
Mutual labels:  search
Sou
简单搜索,一个简单的前端界面。用惯了各种导航首页,满屏幕尽是各种不厌其烦的广告和资讯;尝试自己写个自己的主页。
Stars: ✭ 628 (+2630.43%)
Mutual labels:  search
Defiant.js
http://defiantjs.com
Stars: ✭ 907 (+3843.48%)
Mutual labels:  search
Vue Instantsearch
👀 Algolia components for building search UIs with Vue.js
Stars: ✭ 707 (+2973.91%)
Mutual labels:  search
Duckduckgo
An unofficial DuckDuckGo search API.
Stars: ✭ 6 (-73.91%)
Mutual labels:  search
Natural Language Youtube Search
Search inside YouTube videos using natural language
Stars: ✭ 676 (+2839.13%)
Mutual labels:  search
Ripgrep
ripgrep recursively searches directories for a regex pattern while respecting your gitignore
Stars: ✭ 28,564 (+124091.3%)
Mutual labels:  search
Minisearch
Tiny and powerful JavaScript full-text search engine for browser and Node
Stars: ✭ 737 (+3104.35%)
Mutual labels:  search
Riot
Go Open Source, Distributed, Simple and efficient Search Engine; Warning: This is V1 and beta version, because of big memory consume, and the V2 will be rewrite all code.
Stars: ✭ 6,025 (+26095.65%)
Mutual labels:  search
Libraries.io
📚 The Open Source Discovery Service
Stars: ✭ 903 (+3826.09%)
Mutual labels:  search
Elasticsuite
Smile ElasticSuite - Magento 2 merchandising and search engine built on ElasticSearch
Stars: ✭ 647 (+2713.04%)
Mutual labels:  search
Memacs
What did I do on February 14th 2007? Visualize your (digital) life in Org-mode
Stars: ✭ 711 (+2991.3%)
Mutual labels:  search
Algoliasearch Client Javascript
⚡️ A fully-featured and blazing-fast JavaScript API client to interact with Algolia.
Stars: ✭ 907 (+3843.48%)
Mutual labels:  search
Odsc 2020 nlp
Repository for ODSC talk related to Deep Learning NLP
Stars: ✭ 20 (-13.04%)
Mutual labels:  search
Osint collection
Maintained collection of OSINT related resources. (All Free & Actionable)
Stars: ✭ 809 (+3417.39%)
Mutual labels:  search

simple, fast interval searches for nim

This uses a binary search in a sorted list of intervals along with knowledge of the longest interval. It works when the size of the largest interval is smaller than the average distance between intervals. As that ratio of largest-size::mean-distance increases, the performance decreases. On realistic (for my use-case) data, this is 1000 times faster to query results and >5000 times faster to check for presence than a brute-force method.

Lapper also has a special case seek method when we know that the queries will be in order. This method uses a cursor to indicate that start of the last search and does a linear search from that cursor to find matching intervals. This gives an additional 2-fold speedup over the find method.

API docs and examples in nim-doc format are available here

See the Performance section for how large the intervals can be and still get a performance benefit.

To use this, it's simply required that your type have a start(m) int and stop(m) int method to satisfy the concept used by Lapper

You can install this with nimble install lapper.

Example

import lapper
import strutils

# define an appropriate data-type. it must have a `start(m) int` and `stop(m) int` method.
#type myinterval = tuple[start:int, stop:int, val:int]
# if we want to modify the result, then we have to use a ref object type
type myinterval = ref object
  start: int
  stop: int
  val: int

proc start(m: myinterval): int {.inline.} = return m.start
proc stop(m: myinterval): int {.inline.} = return m.stop
proc `$`(m:myinterval): string = return "(start:$#, stop:$#, val:$#)" % [$m.start, $m.stop, $m.val]

# create some fake data
var ivs = new_seq[myinterval]()
for i in countup(0, 100, 10):
  ivs.add(myinterval(start:i, stop:i + 15, val:0))

# make the Lapper "data-structure"
var l = lapify(ivs)
var empty:seq[myinterval]

assert l.find(10, 20, empty)
var notfound = not l.find(200, 300, empty)
assert notfound

var res = new_seq[myinterval]()

# find is the more general case, l.seek gives a speed benefit when consecutive queries are in order.
echo l.find(50, 70, res)
echo res
# @[(start: 40, stop: 55, val:0), (start: 50, stop: 65, val: 0), (start: 60, stop: 75, val: 0), (start: 70, stop: 85, val: 0)]
for r in res:
  r.val += 1

# or we can do a function on each overlapping interval
l.each_seek(50, 60, proc(a:myinterval) = inc(a.val))
# or
l.each_find(50, 60, proc(a:myinterval) = a.val += 10)

discard l.seek(50, 70, res)
echo res
#@[(start:40, stop:55, val:12), (start:50, stop:65, val:12), (start:60, stop:75, val:1)]

Performance

The output of running bench.nim (with -d:release) which generates 200K intervals with positions ranging from 0 to 50 million and max lengths from 10 to 1M is:

max interval size lapper time lapper seek time brute-force time speedup seek speedup each-seek speedup
10 0.06 0.04 387.44 6983.81 9873.11 9681.66
100 0.05 0.04 384.92 7344.32 10412.97 15200.84
1000 0.06 0.05 375.37 6250.23 7942.50 15703.24
10000 0.15 0.14 377.29 2554.61 2702.13 15942.76
100000 0.99 0.99 377.88 383.36 381.37 16241.61
1000000 12.52 12.53 425.61 34.01 33.96 17762.58

Note that this is a worst-case scenario as we could also simulate a case where there are few long intervals instead of many large ones as in this case. Even so, we get a 34X speedup with lapper.

Also note that testing for presence will be even faster than the above comparisons as it returns true as soon as an overlap is found.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].