def append(self, a): """Append python list a to pcm Intarray.""" l = len(a) arr = _pcm.intArray(l) for i in range(l): arr[i] = a[i] _pcm.PCMarraycopy(self.intarray, arr, l)
def read(self, filename): if self.load: _pcm.PCMfilefree(self.f) self.f = _pcm.PCMfilecreate() self.status = _pcm.PCMfileopen(self.f, filename) else: self.status = _pcm.PCMfileopen(self.f, filename) self.load = True
import PCM_Python as pcmpy import sys if len(sys.argv) < 2: print 'Please provide a file as input' else: f = pcmpy.PCMfilecreate() status = pcmpy.PCMfileopen(f, sys.argv[1]) if status == 0: pcmpy.PCMfilestat(f) print 'Get the first line of ' + sys.argv[1] + ':' status, maxline, length = pcmpy.PCMfilegetline(f, 256) print 'The line is:' + maxline print 'The length is ' + str(length) print '' print 'Get the max line of ' + sys.argv[1] + ':' status, maxline, length = pcmpy.PCMfilegetmaxline(f) print 'The line is:' + maxline print 'The length is ' + str(length) else: print 'Error code: ' + str(status) pcmpy.PCMfilefree(f)
import PCM_Python as pcmpy version = pcmpy.PCMversion() print version a = pcmpy.PCMarraynew("1") b = pcmpy.PCMarraynew("2") pcmpy.PCMarrayinsert(a,0,1) pcmpy.PCMarrayinsert(a,0,5) pcmpy.PCMarrayinsert(a,0,3) pcmpy.PCMarrayinsert(a,0,2) pcmpy.PCMarrayinsert(b,0,3) pcmpy.PCMarrayinsert(b,0,2) arr = pcmpy.intArray(10) for i in range(10): arr[i] = i pcmpy.PCMarraycopy(a,arr,10) #pcmpy.PCMarraymerge(a,b) pcmpy.PCMarrayoutput(a) pcmpy.PCMarraysort(a,3,pcmpy.PCMALGSORTBUBBLE) status, e = pcmpy.PCMarrayfind(a,4,5,pcmpy.PCMALGORIGINFIND) print e pcmpy.PCMarrayoutput(a) status, e = pcmpy.PCMarraydelete(a,0) print str(e)+' was deleted' pcmpy.PCMarrayoutput(a) pcmpy.PCMarraydeleteR(a) pcmpy.PCMarrayoutput(a) pcmpy.PCMarrayfree(a) pcmpy.PCMarrayfree(b)
def __init__(self): self.f = _pcm.PCMfilecreate() self.load = False
def sort(self): """sort pcm Intarray.""" _pcm.PCMarraysort(self.intarray, _pcm.PCMarraylen(self.intarray), self.sortalg)
def output(self): """print pcm Intarray.""" _pcm.PCMarrayoutput(self.intarray)
def __del__(self): _pcm.PCMarrayfree(self.intarray)
def __init__(self, name): self.intarray = _pcm.PCMarraynew(name) self.sortalg = _pcm.PCMALGSORTQUICK
def get_version(): """Returns a string specifying the version of PCM.""" return _pcm.PCMversion()
def stat(self): if self.load and self.status == 0: _pcm.PCMfilestat(self.f) else: print 'Please load file by load method first'
def __del__(self): _pcm.PCMfilefree(self.f) self.load = False
import PCM_Python as pcmpy version = pcmpy.PCMversion() print version a = pcmpy.PCMarraynew("1") b = pcmpy.PCMarraynew("2") pcmpy.PCMarrayinsert(a, 0, 1) pcmpy.PCMarrayinsert(a, 0, 5) pcmpy.PCMarrayinsert(a, 0, 3) pcmpy.PCMarrayinsert(a, 0, 2) pcmpy.PCMarrayinsert(b, 0, 3) pcmpy.PCMarrayinsert(b, 0, 2) arr = pcmpy.intArray(10) for i in range(10): arr[i] = i pcmpy.PCMarraycopy(a, arr, 10) #pcmpy.PCMarraymerge(a,b) pcmpy.PCMarrayoutput(a) pcmpy.PCMarraysort(a, 3, pcmpy.PCMALGSORTBUBBLE) status, e = pcmpy.PCMarrayfind(a, 4, 5, pcmpy.PCMALGORIGINFIND) print e pcmpy.PCMarrayoutput(a) status, e = pcmpy.PCMarraydelete(a, 0) print str(e) + ' was deleted' pcmpy.PCMarrayoutput(a) pcmpy.PCMarraydeleteR(a) pcmpy.PCMarrayoutput(a) pcmpy.PCMarrayfree(a) pcmpy.PCMarrayfree(b)