Skip to content

Generic implementation of the fixed sized BitSet data structure. Work-in-progress

Notifications You must be signed in to change notification settings

adamnemecek/BitSet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BitSet

hey it's me ur fav datastructure, BitSet. This implementation is generic and uses a fixed size unsigned integer as it's backing storage. Yes, you can only store 8, 16, 32, 64 or 128 bits but a lot of times that's enough and this way, it's fast as shit (💩) through the magic of intrinsics.

TRY IT IN YOUR BROWSER

Installation

Use Swift Package Manager.

import PackageDescription

let package = Package(
    name: "BitSet",
    dependencies: [
      .Package(url: "https://github.com/adamnemecek/BitSet.git", majorVersion: 1)
    ]
)

Usage

import BitSet

typealias BitSet64 = BitSet<UInt64>

let b: BitSet64 = [1,2,3,4,10]

print(b.count) /// => 5

print(b.contains(1)) /// => true

print(b.contains(11)) /// => false

let c = b.union([20,30]) /// => BitSet([1,2,3,4,10,20,30])

/// BitSet conforms to SetAlgebra and Collection so all your favorite operations are supported.

Documentation

public struct BitSet<Element: FixedWidthInteger & UnsignedInteger>: SetAlgebra, Collection, ExpressibleByArrayLiteral, CustomStringConvertible, Hashable {
    struct Index {
        /// ...
    }

    var startIndex: Index { get }
    var endIndex: Index { get }
    var count: IndexDistance { get }

    subscript(index: Index) -> Element { get }

    /// and
    func intersection(_ other: BitSet) -> BitSet

    /// or
    func union(_ other: BitSet) -> BitSet

    /// xor
    func symmetricDifference(_ other: BitSet) -> BitSet

}

About

Generic implementation of the fixed sized BitSet data structure. Work-in-progress

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages