Git Product home page Git Product logo

lua_cuckoo_filter_uparse's Introduction

Lua Cuckoo Filter Library

Overview

A bloom filter alternative for approximate set membership tests with deletion support.

Installation

Prerequisites

  • C compiler (GCC 4.7+, Visual Studio 2013, MinGW (Lua 5.1))
  • Lua 5.1, Lua 5.2, or LuaJIT
  • CMake (2.8.7+)

CMake Build Instructions

git clone https://github.com/mozilla-services/lua_cuckoo_filter.git
cd lua_cuckoo_filter 
mkdir release
cd release

# UNIX
cmake -DCMAKE_BUILD_TYPE=release ..
make

# Windows Visual Studio 2013
cmake -DCMAKE_BUILD_TYPE=release -G "NMake Makefiles" ..
nmake

ctest
cpack

Module

Example Usage

require "cuckoo_filter"

local cf = cuckoo_filter.new(1000) -- this will be rounded up to 1024
local found = cf:query("test")
-- found == false
cf:add("test")
found = cf:query("test")
-- found == true

API Functions

new

require "cuckoo_filter"
local cf = cuckoo_filter.new(1024)

Import the Lua cuckoo_filter via the Lua 'require' function. The module is globally registered and returned by the require function.

Arguments

  • items (unsigned) The maximum number of items to be inserted into the filter (must be >= 4). Items are grouped into buckets of four and the number of buckets will be rounded up to the closest power of two if necessary. The fingerprint size is currently fixed at sixteen bits so the false positive rate is 0.00012.

Return

  • cuckoo_filter userdata object.

version

require "cuckoo_filter"
local v = cuckoo_filter.version()
-- v == "0.1.0"

Returns a string with the running version of cuckoo_filter.

Arguments

  • none

Return

  • Semantic version string

API Methods

add

local added = cf:add(key)

Adds an item to the cuckoo filter. This method works a little differently than the standard algorithm; a lookup is performed first. Since we must handle duplicates we consider any collision within the bucket to be a duplicate.

Arguments

  • key (string/number) The key to add in the cuckoo filter.

Return

  • True if the key was added, false if it already existed.

delete

local deleted = cf:delete(key)

Deletes an item to the cuckoo filter.

Arguments

  • key (string/number) The key to delete in the cuckoo filter.

Return

  • True if the key was deleted, false if it didn't exist.

query

local found = cf:query(key)

Checks for the existence of the key in the cuckoo filter.

Arguments

  • key (string/number) The key to lookup in the cuckoo filter.

Return

  • True if the key exists, false if it doesn't.

count

local total = cf:count()

Returns the number of items in the cuckoo filter.

Arguments

  • none

Return

  • Returns the number of distinct items currently in the set.

clear

cf:clear()

Resets the cuckoo filter to an empty set.

Arguments

  • none

Return

  • none

lua_cuckoo_filter_uparse's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.