Example #1
0
 def Load(this, serialization):
     keys = this.keys
     values = this.values
     if len(keys) > 0:
         raise BplusTreeException, "cannot load into non-empty bucket"
     index = 0
     bytecount = len(serialization)
     while index < bytecount:
         keylength = BufferFile.RetrieveInt(serialization, index)
         index += BufferFile.INTSTORAGE
         nextindex = index + keylength
         keybytes = serialization[index:nextindex]
         index = nextindex
         (key, dummy) = DECODER(keybytes)
         valuelength = BufferFile.RetrieveInt(serialization, index)
         index += BufferFile.INTSTORAGE
         nextindex = index + valuelength
         valuebytes = serialization[index:nextindex]
         (value, dummy) = DECODER(valuebytes)
         index = nextindex
         keys.append(key)
         values.append(value)
     if index != bytecount:
         raise BplusTreeException, "error counting bytes " + repr(
             (index, bytecount))
Example #2
0
 def GetChunk(this, HeadBufferNumber):
     (buffer, buffertype,
      nextBufferNumber) = this.ParseBuffer(HeadBufferNumber)
     if buffertype != HEAD:
         raise LinkedFileException, "head buffer not marked head " + repr(
             HeadBufferNumber)
     length = BufferFile.RetrieveInt(buffer)
     #print "getting", length
     #print "buffer=", repr(buffer)
     piece = buffer[BufferFile.INTSTORAGE:]
     lengthToRead = length
     pieces = []
     while lengthToRead > 0:
         lpiece = len(piece)
         if lengthToRead < lpiece:
             pieces.append(piece[:lengthToRead])
             break
         pieces.append(piece)
         #print "read", repr(piece)
         lengthToRead -= lpiece
         #print "length to read", lengthToRead
         if (lengthToRead > 0):
             (piece, buffertype,
              nextBufferNumber) = this.ParseBuffer(nextBufferNumber)
             if buffertype != BODY:
                 raise LinkedFileException, "body buffer not marked body " + repr(
                     nextBufferNumber)
     return string.join(pieces, "")
 def readHeader(this):
     f = this.fromfile
     f.seek(this.seekStart)
     header = f.read(this.headersize)
     index = len(HEADERPREFIX)
     prefix = header[:index]
     if prefix != HEADERPREFIX:
         raise BplusTreeException, "bad prefix %s should be %s" % (repr(
             header[:index]), repr(HEADERPREFIX))
     index += 1  # skip version
     this.NodeSize = BufferFile.RetrieveInt(header, index)
     index += BufferFile.INTSTORAGE
     this.KeyLength = BufferFile.RetrieveInt(header, index)
     index += BufferFile.INTSTORAGE
     CultureId = BufferFile.RetrieveInt(header, index)
     index += BufferFile.INTSTORAGE
     this.rootSeek = BufferFile.RetrieveLong(header, index)
     index += BufferFile.LONGSTORAGE
     this.freeHeadSeek = BufferFile.RetrieveLong(header, index)
     this.SanityCheck()
Example #4
0
 def readHeader(this):
     f = this.fromfile
     f.seek(this.seekStart)
     buffer = f.read(this.headersize)
     index = len(HEADERPREFIX)
     prefix = buffer[:index]
     if prefix != HEADERPREFIX:
         raise LinkedFileException, "bad header prefix"
     remainder = buffer[index + 1:]
     this.buffersize = BufferFile.RetrieveInt(remainder, 0)
     this.FreeListHead = BufferFile.RetrieveLong(remainder,
                                                 BufferFile.INTSTORAGE)
     #print "<br>linkedfile readheader buffersize=", this.buffersize, "freehead=", this.FreeListHead
     this.headerDirty = False
     this.sanityCheck()