GithubHelp home page GithubHelp logo

Comments (4)

andreasvc avatar andreasvc commented on June 11, 2024 1

It sounds like you should map your keys to integers and use https://roaringbitmap.readthedocs.io/en/latest/#roaringbitmap.MultiRoaringBitmap.intersection

from roaringbitmap.

andreasvc avatar andreasvc commented on June 11, 2024

A MultiRoaringBitmap manages and owns the storage in memory or on disk of the bitmaps it contains, so returning a MultiRoaringBitmap requires copying the data. If you do want a new instance of MultiRoaringBitmap with copies, you can do MultiRoaringBitmap(mrb[0:5]) as in your example.

Do you have a use case where having slices without making copies is crucial? It is probably possible to create a version of MultiRoaringBitmap that references a slice of another one, but I'm not sure implementing that is worth the effort ...

from roaringbitmap.

remiadon avatar remiadon commented on June 11, 2024

My use case is the following

I am using Bitmaps to represent a transactional database : for every item in my database, I keep track of transaction ids where this item occurred.

>> from collections import defaultdict
>> from roaringbitmap import RoaringBitmap
>> database = [['milk', 'chocolate', 'banana'], ['banana', 'nuts', 'milk'], ['orange juice', 'milk', 'chocolate']]
>> d = defaultdict(RoaringBitmap)
>> for idx, transaction in enumerate(database):
>>    for item in transaction:
>>       d[item].add(idx)

>> d
defaultdict(roaringbitmap.RoaringBitmap,
            {'milk': RoaringBitmap({0, 1, 2}),
             'chocolate': RoaringBitmap({0, 2}),
             'banana': RoaringBitmap({0, 1}),
             'nuts': RoaringBitmap({1}),
             'orange juice': RoaringBitmap({2})})

Let's imagine I want to know how many times 'milk' and 'chocolate' occurred together :

from functools import reduce
>> keys = ['milk', 'chocolate'] 
>> len(reduce(RoaringBitmap.intersection, (d[k] for k in keys)))
2

As my database definition is static (I ingest data only once and do not modify my data representation), I was hopping to get better performance using MultiRoaringBitmap, computing intersections on subsets of it

from roaringbitmap.

remiadon avatar remiadon commented on June 11, 2024

Right on point,
thanks for the support

Closing this

from roaringbitmap.

Related Issues (20)

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.