Giter Club home page Giter Club logo

bitmap's Introduction

BitMap for python

This package provides a BitMap class which is an array of bits stored in compact format.

Installation

bitmap can be installed from pip:

$ sudo pip install bitmap

Functions

  • BitMap(maxnum): construct a BitMap object with maxnum bits
  • set(pos): set the bit at position pos to 1
  • reset(pos): reset the bit at position pos to 0
  • flip(pos): flip the bit at position pos
  • count(): return the number of 1s
  • size(): return the size of the BitMap
  • test(pos): check if bit at position pos has been set to 1
  • any(): check if any bit in the BitMap has been set to 1
  • none(): check if none of the bits in the BitMap has been set to 1
  • all(): check if all bits in the BitMap has been set to 1
  • nonzero(): return indexes of all non-zero bits
  • tostring(): convert a BitMap object to 0 and 1 string
  • fromstring(bitstring): create a BitMap object from 0 and 1 string

Examples

from bitmap import BitMap
bm = BitMap(32)
print bm.tostring()
bm.set(1)
print bm.tostring()

bm = BitMap.fromstring("00011101")
print bm.tostring()
bm.flip(1)
print bm.tostring()

bitmap's People

Contributors

ailurophile avatar cristianowa avatar mstyushin avatar wanji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bitmap's Issues

Wrong bitmap size

When try to create a new bitmap with size "500" it return a bitmap with 504 position.
This is really annoying.

fromhexstring() needs integer division.

Calling str(len(hexstring) / 4) in the second argument of format() causes an error as "Precision not allowed in integer format specifier" (VS error message). Float division returns a float value which format() can't use.

Possible fixes:

  • str(len(hexstring) // 4)
  • str(int(len(hexstring)) / 4)

bitmap 1 and 0 symmetrical

Currently the bitmap have to be initialized as all zero.

It would be nice to add argument in constructor to preset all bits to 1.

And it would be awesome to add zero() method to return all the indexes of zero bits.

License?

Hi: what would be the license for your fine code? Thanks!

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.