项目作者: adamnemecek

项目描述 :
Generic implementation of the fixed sized BitSet data structure. Work-in-progress
高级语言: Swift
项目地址: git://github.com/adamnemecek/BitSet.git
创建时间: 2017-11-27T16:56:04Z
项目社区:https://github.com/adamnemecek/BitSet

开源协议:

下载


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.

  1. import PackageDescription
  2. let package = Package(
  3. name: "BitSet",
  4. dependencies: [
  5. .Package(url: "https://github.com/adamnemecek/BitSet.git", majorVersion: 1)
  6. ]
  7. )

Usage

  1. import BitSet
  2. typealias BitSet64 = BitSet<UInt64>
  3. let b: BitSet64 = [1,2,3,4,10]
  4. print(b.count) /// => 5
  5. print(b.contains(1)) /// => true
  6. print(b.contains(11)) /// => false
  7. let c = b.union([20,30]) /// => BitSet([1,2,3,4,10,20,30])
  8. /// BitSet conforms to SetAlgebra and Collection so all your favorite operations are supported.

Documentation

  1. public struct BitSet<Element: FixedWidthInteger & UnsignedInteger>: SetAlgebra, Collection, ExpressibleByArrayLiteral, CustomStringConvertible, Hashable {
  2. struct Index {
  3. /// ...
  4. }
  5. var startIndex: Index { get }
  6. var endIndex: Index { get }
  7. var count: IndexDistance { get }
  8. subscript(index: Index) -> Element { get }
  9. /// and
  10. func intersection(_ other: BitSet) -> BitSet
  11. /// or
  12. func union(_ other: BitSet) -> BitSet
  13. /// xor
  14. func symmetricDifference(_ other: BitSet) -> BitSet
  15. }