def enumerate(self): index, res = 0, self.header() while bitmap.size(res) > 1: # check to see if the msize moves us to a header bit that's unset if bitmap.int(bitmap.get(res, 0, 1)) == 0: fixup = bitmap.runlength(res, 0, 0) logging.warn('Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.'.format(index, fixup)) res, _ = bitmap.consume(res, fixup) if bitmap.size(res) == 0: break # search for how long this run is msize = bitmap.runlength(res, 0, 1) + 1 yield index, msize # consume msize bits index += msize res, _ = bitmap.consume(res, msize) return
def used(self): m, res = self.getparent(magazine_t), self.header() index = m['mag_bytes_free_at_start'].int() / self.QUANTUM sentinel = (m['num_bytes_in_magazine'].int() - m['mag_bytes_free_at_end'].int()) / self.QUANTUM while index <= sentinel: # check to see if the msize moves us to a header bit that's unset if bitmap.int(bitmap.get(res, 0, 1)) == 0: fixup = bitmap.runlength(res, 0, 0) logging.warn('Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.'.format(index, fixup)) res, _ = bitmap.consume(res, fixup) if bitmap.size(res) == 0: break # search for how long this run is msize = bitmap.runlength(res, 0, 1) + 1 yield index, msize # consume msize bits index += msize res, _ = bitmap.consume(res, msize) return
def enumerate(self): index, res = 0, self.header() while bitmap.size(res) > 1: # check to see if the msize moves us to a header bit that's unset if bitmap.int(bitmap.get(res, 0, 1)) == 0: fixup = bitmap.runlength(res, 0, 0) logging.warn( 'Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.' .format(index, fixup)) res, _ = bitmap.consume(res, fixup) if bitmap.size(res) == 0: break # search for how long this run is msize = bitmap.runlength(res, 0, 1) + 1 yield index, msize # consume msize bits index += msize res, _ = bitmap.consume(res, msize) return
def used(self): m, res = self.getparent(magazine_t), self.header() index = m['mag_bytes_free_at_start'].int() / self.QUANTUM sentinel = (m['num_bytes_in_magazine'].int() - m['mag_bytes_free_at_end'].int()) / self.QUANTUM while index <= sentinel: # check to see if the msize moves us to a header bit that's unset if bitmap.int(bitmap.get(res, 0, 1)) == 0: fixup = bitmap.runlength(res, 0, 0) logging.warn( 'Index {:d} of header is not set. Possibly corrupt? Forced to consume {:d} bits.' .format(index, fixup)) res, _ = bitmap.consume(res, fixup) if bitmap.size(res) == 0: break # search for how long this run is msize = bitmap.runlength(res, 0, 1) + 1 yield index, msize # consume msize bits index += msize res, _ = bitmap.consume(res, msize) return
def busyfree(self): inuse = self.inuse() for index, msize in self.used(): res = bitmap.get(inuse, index, 1) yield index, msize, bool(bitmap.int(res)) return
def freeQ(self, index): '''Returns whether the chunk at the specified index is free''' index = self.__check_header(index) inuse = self.inuse() freeQ = bitmap.int(bitmap.get(inuse, index, 1)) return bool(freeQ == 0)
def __check_header(self, index): header = self.header() headerQ = bitmap.int(bitmap.get(header, index, 1)) if headerQ == 0: raise ValueError('index {:d} is not a header'.format(index)) return index