GithubHelp home page GithubHelp logo

roaringbitmap / swiftroaring Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 5.0 16.29 MB

A better compressed bitset in Swift http://roaringbitmap.org/

License: BSD 3-Clause "New" or "Revised" License

Swift 100.00%

swiftroaring's Issues

Use fastbase64 for encoding

Hello, did you consider adding support for base64 encoding to roaring? I imagine that fastbase64 would do the trick.

This is probably more of a croaring issue that SwiftRoaring but we discussed base64 encoding here.

Swift - RoaringBitmap - Serialize to base64

Hello, I am trying to serialise a bloom filter generated in a roaring bitmap format to a base64 string, so that I can save it in MongoDB. But the function portableSerialize is a bit tricky for me.

I am so far just testing how it works and I generate a random bloom filter values that I later try to convert to buffer -> to data -> to base64:

func generateBloomFilterData(){
    let bitmap = RoaringBitmap()
    for i in 0..<50 { 
        let random = arc4random_uniform(2)
        if random == 0 {
            bitmap.add(UInt32(i))
        } 
    }  
    let count = (Int(bitmap.count) * MemoryLayout<Int8>.size)
    var buffer = [Int8](repeating: 0, count: count)
    _ = bitmap.portableSerialize(buffer: &buffer)
    let uintBuffer = buffer.map { UInt8(bitPattern: $0) }
    let bufferData = Data(uintBuffer)
    let base64String = bufferData()
    print("buffer size: \(buffer.count), \(uintBuffer.count), base64: \(bufferData.base64EncodedString())")
    //-> send base64 string to database
}

This generates an error:

malloc: MallocStackLogging: attempting to release an index out of
bounds

The console shows:

buffer size: 20, 20, base64: OjAAAAEAAAAAABMAEAAAAAMABQA=

Is there a way how to simply generate a base64 string out of the above generated RoaringBitmap() ?

Confusing semantics of maximum

I'm confused by the intended semantics of max. In the following example, we have two sets, one which contains a zero and one which is empty. However max returns 0 in both cases. How can I distinguish these cases? Am I supposed to be checking if the set is empty?

func testFirst() {
    // empty
    let a: RoaringBitmap = []
    print("empty")
    for e in a {
        print(e)
    }
    print("a max", a.max())

    // empty
    print("has 0")
    let b: RoaringBitmap = [0]
    for e in b {
        print(e)
    }

    print("b max", b.max())
}

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.