Git Product home page Git Product logo

filters's Introduction

Filter

This is a library for implementing Bloom and Cuckoo filters in Swift. The library provides two filters BloomFilter and CuckooFilter which can be used to filter data, reduce database access, crawlers, etc.

CuckooFilter is under development, details are in cuckoo_filter branch

Installation

The library can be added as dependency via swift package manager or Cocoapods .

SPM

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "YourPackage",
    products: [
        .library(name: "YourPackage", targets: ["YourPackage"]),
    ],
    dependencies: [
        .package(url: "https://github.com/panicfrog/Filters.git", from: "0.0.2"),
    ],
    targets: [
        .target(
            name: "YourPackage",
            dependencies: ["Filter"]),
    ]
)

Xcode

File -> Add packages https://github.com/panicfrog/Filters.git

Cocoapods

pod 'Filters', '~> 0.0.2'

Usage

// create bloom filter with `BloomFilterBuilder`
let bloom = BloomFilterBuilder.default
        .with(maxElements: max)   // the maximum number of elements expected to be added
        .with(hasher: Xxhasher()) // default is Murmurhash3_x86_32
        .with(safety: true)       // thread safety
        .build()
// add item to filter
bloom.add("hello")
// determine whether item is comtained in the bloom filter
bloom.contains("hello")

you can also use mmap to mapping bloom's bitmap to a file

// create bloom filter with `BloomFilterBuilder`, that can mapping bitmap to file using mmap
let url = URL(string: "<path your want to mapping>")!
let bloom = BloomFilterBuilder.default
  .with(maxElements: max)
  .with { m in
    try! MmapBitmap(m, path: url)
  }.build()
// add item to filter
bloom.add("item1")
// determine whether item is comtained in the bloom filter
bloom.contains("item1")

API

You can clone the warehouse code, and then use Swift-DocC to produce the api documentation for local preview, and the online documentation is coming soon ...

swift package --disable-sandbox preview-documentation --target Filter

License

This library is licensed under the MIT License. See the LICENSE file for more details.

filters's People

Contributors

panicfrog avatar

Watchers

 avatar

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.