def Load(this, buffer): this.Clear() indicator = ord(buffer[0]) this.isLeaf = (indicator == LEAF) if indicator not in NONFREE: raise BplusTreeException, "can't parse buffer not marked non-free" index = 1 this.ChildBufferNumbers[0] = BufferFile.RetrieveLong(buffer, index) index += BufferFile.LONGSTORAGE maxLength = this.owner.KeyLength maxKeyPayload = maxLength - BufferFile.SHORTSTORAGE lastkey = "" keys = this.ChildKeys numbers = this.ChildBufferNumbers for KeyIndex in xrange(this.Size): KeyLength = BufferFile.RetrieveShort(buffer, index) index += BufferFile.SHORTSTORAGE key = None if (KeyLength == 0): key = "" elif (KeyLength > 0): section = buffer[index:index + KeyLength] (key, nchars) = DECODER(section) keys[KeyIndex] = key index += maxKeyPayload seekPosition = BufferFile.RetrieveLong(buffer, index) numbers[KeyIndex + 1] = seekPosition index += BufferFile.LONGSTORAGE
def parseFreeBuffer(this, buffernumber): freesize = 1 + BufferFile.LONGSTORAGE buffer = this.buffers.getBuffer(buffernumber, freesize) indicator = ord(buffer[0]) if indicator != FREE: raise BplusTreeException, "free buffer not marked free " + repr( buffernumber) return BufferFile.RetrieveLong(buffer, 1)
def ParseBuffer(this, bufferNumber): if bufferNumber < 0: raise LinkedFileException, "buffer numbers cannot be negative " + repr( bufferNumber) thebuffer = this.buffers.getBuffer(bufferNumber) typ = ord(thebuffer[0]) nextBufferNumber = BufferFile.RetrieveLong(thebuffer, 1) realbuffer = thebuffer[BUFFEROVERHEAD:] #print "<br>got", bufferNumber, typ, repr(realbuffer), nextBufferNumber return (realbuffer, typ, nextBufferNumber)
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()
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()