Code Monkey home page Code Monkey logo

tibitset's Introduction

tibitset

A simple bitset container for Rust, meant to be a replacement for HashSet

Please read the API documentation here

build_status crates

Philosophy

This crate is a fork from fixedbitset with added genericity over its bit indexing type. It is the same idea like TiVec is for Vec, a collection which you can use with a custom index type which is not usize. It's also a nearly-drop-in replacement for HashSet which you can use when you have a limited index space with mostly full collections.

Usage

[dependencies]
tibitset = "0.1"
use tibitset::TiBitSet;
use std::convert::TryInto;

struct CustomIndex(pub u16);

impl From<usize> for CustomIndex {
    fn from(value: usize) -> Self {
        CustomIndex(value.try_into().expect("value too large to fit u16"))
    }
}
impl Into<usize> for CustomIndex {
    fn into(self) -> usize {
        self.0.into()
    }
}

let fb: TiBitSet::<CustomIndex>::with_capacity(10);
fb.set(CustomIndex(2), true);
assert!(!fb.contains(CustomIndex(1)));
assert!(fb.contains(CustomIndex(2)));

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This file may not be copied, modified, or distributed except according to those terms.

tibitset's People

Contributors

atouchet avatar barafael avatar bestouff avatar bluss avatar emberian avatar fuine avatar jakobhellermann avatar jonimake avatar jrraymond avatar karelpeeters avatar kennytm avatar keshavsn avatar lovasoa avatar luizirber avatar mneumann avatar nwn avatar shirousagi-san avatar sunshowers avatar vks avatar wirelyre avatar

Stargazers

 avatar  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.