Beispiel #1
0
 def _reinit(self, pdspath):
     if self.ofs:
         self.ofs.gc()
         self.ofs.close()
     if self.pstor:
         self.pstor.close()
     self.pstor, self.ofs = ostore.init_ostore(pdspath)
     self.ptrieObj = Ptrie(self.pstor)
     self.root = ptrie.Nulltrie # Start with Nulltrie as root
Beispiel #2
0
 def __init__(self):
     self.pstor, self.ofs = ostore.init_ostore()
     self.ptrieObj = ptrie.Ptrie(self.pstor)
     self.root = ptrie.Nulltrie # Start with Nulltrie as root
     self.count = 0
Beispiel #3
0
            yield tmpl
            return
        for i in range(2, length + 1):
            head = tmpl[:i]
            tail = tmpl[i:]
            yield (head[::-1] + tail)

    def build(self):
        ''' Builds the pancake ptrie list one level at a time. Build stops when
        a 'pcakeTrie'' is empty, which means that there are no new sequences left,
        in other words, we have enumerated all permutations of the n pancakes. '''
        i = 0
        while True:
            print "Level %d" % i
            pcakeTrie = self._mkPcakeTrie(self.pcakeTrieList)
            if pcakeTrie is ptrie.Nulltrie:
                break
            i += 1
            self.pcakeTrieList = self.plistObj.cons(pcakeTrie, self.pcakeTrieList)


if __name__ == "__main__":
    import sys

    num = int(sys.argv[1])
    pstor, ofs = ostore.init_ostore()
    pcakeObj = Pancake(num, pstor, ofs)
    pcakeObj.build()
    ofs.close()
    pstor.close()
Beispiel #4
0
        if not i:
            # compare not found in ll
            raise RuntimeError("compare value not found in list!")
        newll = self.cons(newvalue, i)
        while stack:
            n = stack.pop()
            newll = self.cons(self.car(n), newll)
        return newll


if __name__ == '__main__':
    import os
    import ostore

    # Global PDS
    global_pstor, oidfs = ostore.init_ostore()
    plistObj = Plist(global_pstor)

    ll = plistObj.plist('Smurfette', 'Tracker', 'Lazy', 'Brainy')
    print ll
    ll = plistObj.insertAfter(ll, 'Tracker', 'PapaSmurf')
    res = plistObj.map(lambda n: "*" + n + "*", ll)
    print res

    # save
    oidfs.store(ll, "The Smurfs")
    oidfs.gc()

    # load
    global_pstor, oidfs = ostore.init_ostore()
    ll = oidfs.load("The Smurfs")