GithubHelp home page GithubHelp logo

bgamari / bitset Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambda-llama/bitset

1.0 3.0 0.0 5.53 MB

A compact functional set data structure

Home Page: http://hackage.haskell.org/package/bitset

License: MIT License

Haskell 30.11% C 69.27% Shell 0.61%

bitset's Introduction

bitset Build Status

A bit set is a compact data structure, which maintains a set of members from a type that can be enumerated (i. e. has an Enum instance). Current implementation is abstract with respect to conatiner type, so any numeric type with Bits instance can be used as a container.

Here's a usage example for a dynamic bit set, which uses a tweaked version of Integer for storing bits:

import Data.BitSet (BitSet, (\\))
import qualified Data.BitSet as BitSet

data Color = Red | Green | Blue deriving (Show, Enum)

main :: IO ()
main = print $ bs \\ BitSet.singleton Blue where
  bs :: BitSet Color
  bs = BitSet.fromList [Red, Green, Blue]

The API is exactly the same for a static bitset, based on native Word. Here's an example from [hen] hen library, which uses Data.BitSet to store Xen domain status flags:

import qualified Data.BitSet.Word as BS

data DomainFlag = Dying
                | Crashed
                | Shutdown
                | Paused
                | Blocked
                | Running
                | HVM
                | Debugged
    deriving (Enum, Show)

isAlive :: DomainFlag -> Bool
isAlive = not . BS.null . BS.intersect (BS.fromList [Crashed, Shutdown])

Benchmarks

To run benchmarks benchmarks, configure cabal with benchmarks and build:

$ cabal-dev install-deps --enable-benchmarks && cabal-dev build
$ ./dist/build/bitset-benchmarks/bitset-benchmarks -o dist/bench.html

bitset's People

Contributors

superbobry avatar knsd avatar

Stargazers

Carter Tazio Schonwald avatar

Watchers

James Cloos avatar Ben Gamari avatar  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.