mirror of
https://github.com/heqin-zhu/algorithm.git
synced 2024-03-22 13:30:46 +08:00
Add sort codes and notes
This commit is contained in:
commit
b15dd20c0e
100
codes/dataStructure/8Astar.py
Normal file
100
codes/dataStructure/8Astar.py
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
isVisited = [0]*362880 # 0 for not visited,1 for occured,2 for visited
|
||||||
|
fac = [1,1,2,6,24,120,720,5040,40320]
|
||||||
|
lf = len(fac)
|
||||||
|
h = [[0,1,2,1,2,3,2,3,4],
|
||||||
|
[1,0,1,2,1,2,3,2,3],
|
||||||
|
[2,1,0,3,2,1,4,3,2],
|
||||||
|
[1,2,3,0,1,2,1,2,3],
|
||||||
|
[2,1,2,1,0,1,2,1,2],
|
||||||
|
[3,2,1,2,1,0,3,2,1],
|
||||||
|
[2,3,4,1,2,3,0,1,2],
|
||||||
|
[3,2,3,2,1,2,1,0,1],
|
||||||
|
[4,3,2,3,2,1,2,1,0]]
|
||||||
|
|
||||||
|
def cantor(s):
|
||||||
|
sum = 0
|
||||||
|
ls = len(s)
|
||||||
|
for i in range(ls):
|
||||||
|
count = 0
|
||||||
|
for j in range(i+1,ls):
|
||||||
|
if s[i] > s[j]: count +=1
|
||||||
|
sum += count*fac[lf-i-1]
|
||||||
|
return sum
|
||||||
|
|
||||||
|
que = []
|
||||||
|
dir = {-3:'u',1:'r',3:'d',-1:'l'}
|
||||||
|
class state:
|
||||||
|
flag = True
|
||||||
|
def __init__(self,s,x,f,step=0,last=0):
|
||||||
|
self.x = x
|
||||||
|
self.s = list(s)
|
||||||
|
self.step = step
|
||||||
|
self.path = []
|
||||||
|
self.last = last
|
||||||
|
self.f = f
|
||||||
|
def can(self):
|
||||||
|
cans = [-1,1,3,-3]
|
||||||
|
if self.last in cans :
|
||||||
|
cans.remove(-self.last)
|
||||||
|
if self.x<3:
|
||||||
|
cans.remove(-3)
|
||||||
|
if self.x>5:
|
||||||
|
cans.remove(3)
|
||||||
|
if self.x%3 is 0:
|
||||||
|
cans.remove(-1)
|
||||||
|
if self.x%3 is 2:
|
||||||
|
cans.remove(1)
|
||||||
|
return cans
|
||||||
|
def move(self):
|
||||||
|
cans = self.can()
|
||||||
|
for i in cans:
|
||||||
|
s = list(self.s)
|
||||||
|
tmp = self.x + i
|
||||||
|
s[self.x] = s[tmp]
|
||||||
|
s[tmp] = '9'
|
||||||
|
ct = cantor(s)
|
||||||
|
if isVisited[ct] != 2 :
|
||||||
|
val = int(s[self.x])
|
||||||
|
f = h[8][tmp] +h[val-1][self.x]-h[8][self.x]-h[val-1][tmp]+self.step+1
|
||||||
|
new = state(s,tmp,f,self.step +1,i)
|
||||||
|
new.path = self.path + [dir[i]]
|
||||||
|
if isVisited[ct] == 1:
|
||||||
|
for i,node in enumerate(que):
|
||||||
|
if mew.s == node.s:
|
||||||
|
del que[i]
|
||||||
|
break
|
||||||
|
else:isVisited[ct] = 1
|
||||||
|
if que == []:
|
||||||
|
que.append(new)
|
||||||
|
continue
|
||||||
|
for i,node in enumerate(que):
|
||||||
|
if new.f<=node.f:
|
||||||
|
que.insert(i,new)
|
||||||
|
def solvable(s):
|
||||||
|
reverse = 0
|
||||||
|
for i in range(8):
|
||||||
|
if s[i] is '9':continue
|
||||||
|
for j in range(i+1,9):
|
||||||
|
if s[i]>s[j]:reverse +=1
|
||||||
|
if reverse % 2 is 0:return True
|
||||||
|
else:return False
|
||||||
|
def getPath(s,index):
|
||||||
|
f = 0
|
||||||
|
for i,j in enumerate(s):
|
||||||
|
f+=h[int(j)-1][i]
|
||||||
|
que.append(state(s,index,f,0,0))
|
||||||
|
while que != []:
|
||||||
|
cur = que.pop(0)
|
||||||
|
ct = cantor(cur.s)
|
||||||
|
isVisited[ct] = 2
|
||||||
|
if ct is 0:
|
||||||
|
return cur.path
|
||||||
|
cur.move()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
s=input()
|
||||||
|
index = s.find('x')
|
||||||
|
s =list(s)
|
||||||
|
s[index] = '9'
|
||||||
|
if solvable(s):print(''.join(getPath(s,index)))
|
||||||
|
else:print('unsolvable')
|
61
codes/dataStructure/EIGHT.py
Normal file
61
codes/dataStructure/EIGHT.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
from colectons import deque
|
||||||
|
isVisted = [0]*362880
|
||||||
|
fac = [1,2,6,24,120,720,5040,40320]
|
||||||
|
lf = len(fac)
|
||||||
|
x= '9'
|
||||||
|
def cantor(s):
|
||||||
|
sum = 0
|
||||||
|
ls = len(s)
|
||||||
|
for i in range(ls):
|
||||||
|
count = 0
|
||||||
|
for j in range(i+1;ls):
|
||||||
|
if s[i] > s[j]: count +=1
|
||||||
|
sum += count*fac[lf-i-1]
|
||||||
|
return sum
|
||||||
|
|
||||||
|
que = deque()
|
||||||
|
class state:
|
||||||
|
def __init__(self,s,p,step=0,last=0):
|
||||||
|
self.x = p
|
||||||
|
self.s = list(s)
|
||||||
|
self.step = step
|
||||||
|
self.path = []
|
||||||
|
self.last = last
|
||||||
|
def move(self):
|
||||||
|
dir = [-3:'u',1:'r',3:'d',-1:'l']
|
||||||
|
if self.last in dir :
|
||||||
|
del dir[-self.last]
|
||||||
|
if self.x<3:
|
||||||
|
del dir[-3]
|
||||||
|
if self.x>5:
|
||||||
|
del dir[3]
|
||||||
|
if self.x%3 is 0:
|
||||||
|
del dir[-1]
|
||||||
|
if self.x%3 is 2:
|
||||||
|
del dir[1]
|
||||||
|
for i in dir.keys():
|
||||||
|
s = list(self.s)
|
||||||
|
tmp = self.x + i
|
||||||
|
s[self.x] = s[tmp]
|
||||||
|
s[tmp] = x
|
||||||
|
if not isVisted[cantor(s)]:
|
||||||
|
new = state(s,tmp,self.step +1,i)
|
||||||
|
new.path = self.path + [dir[i]]
|
||||||
|
que.append(new)
|
||||||
|
|
||||||
|
def getPath(s):
|
||||||
|
index = s.find('x')
|
||||||
|
s =list(s)
|
||||||
|
s[index] = '9'
|
||||||
|
que.append(state(s,index,0,0))
|
||||||
|
while que != deque():
|
||||||
|
cur = que.popleft()
|
||||||
|
ct = cantor(cur.s)
|
||||||
|
if ct is 362879:
|
||||||
|
return cur.path
|
||||||
|
isVisted[] = 1
|
||||||
|
cur.move()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
s=input()
|
||||||
|
print(''.join(getPath(s)))
|
201
codes/dataStructure/allOoneDS.py
Normal file
201
codes/dataStructure/allOoneDS.py
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
class node:
|
||||||
|
def __init__(self,val=None,data_mp=None,pre=None,next=None):
|
||||||
|
self.val=val
|
||||||
|
self.data_mp = {} if data_mp is None else data_mp
|
||||||
|
self.pre=pre
|
||||||
|
self.next=next
|
||||||
|
def __lt__(self,nd):
|
||||||
|
return self.val<nd.val
|
||||||
|
def getOne(self):
|
||||||
|
if not self.data_mp:
|
||||||
|
return ''
|
||||||
|
else:return list(self.data_mp.items())[0][0]
|
||||||
|
def __getitem__(self,key):
|
||||||
|
return self.data_mp[key]
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.data_mp)
|
||||||
|
def __delitem__(self,key):
|
||||||
|
del self.data_mp[key]
|
||||||
|
def __setitem__(self,key,val):
|
||||||
|
self.data_mp[key]= val
|
||||||
|
def isEmpty(self):
|
||||||
|
return self.data_mp=={}
|
||||||
|
def __repr__(self):
|
||||||
|
return 'node({},{})'.format(self.val,self.data_mp)
|
||||||
|
class doubleLinkedList:
|
||||||
|
def __init__(self):
|
||||||
|
self.head= self.tail = node(0)
|
||||||
|
self.head.next = self.head
|
||||||
|
self.head.pre = self.head
|
||||||
|
self.chain_mp={0:self.head}
|
||||||
|
def __str__(self):
|
||||||
|
li = list(self.chain_mp.values())
|
||||||
|
li = [str(i) for i in li]
|
||||||
|
return 'min:{}, max:{}\n'.format(self.head.val,self.tail.val) \
|
||||||
|
+ '\n'.join(li)
|
||||||
|
def getMax(self):
|
||||||
|
return self.tail.getOne()
|
||||||
|
def getMin(self):
|
||||||
|
return self.head.getOne()
|
||||||
|
def addIncNode(self,val):
|
||||||
|
# when adding a node,inc 1, so it's guranted that node(val-1) exists
|
||||||
|
self.chain_mp[val].pre= self.chain_mp[val-1]
|
||||||
|
self.chain_mp[val].next= self.chain_mp[val-1].next
|
||||||
|
self.chain_mp[val-1].next.pre = self.chain_mp[val-1].next = self.chain_mp[val]
|
||||||
|
def addDecNode(self,val):
|
||||||
|
# when adding a node,dec 1, so it's guranted that node(val+1) exists
|
||||||
|
self.chain_mp[val].next= self.chain_mp[val+1]
|
||||||
|
self.chain_mp[val].pre= self.chain_mp[val+1].pre
|
||||||
|
self.chain_mp[val+1].pre.next = self.chain_mp[val+1].pre = self.chain_mp[val]
|
||||||
|
def addNode(self,val,dec=False):
|
||||||
|
self.chain_mp[val] = node(val)
|
||||||
|
if dec:self.addDecNode(val)
|
||||||
|
else:self.addIncNode(val)
|
||||||
|
if self.tail.val<val:self.tail = self.chain_mp[val]
|
||||||
|
if self.head.val>val or self.head.val==0:self.head= self.chain_mp[val]
|
||||||
|
def delNode(self,val):
|
||||||
|
self.chain_mp[val].next.pre = self.chain_mp[val].pre
|
||||||
|
self.chain_mp[val].pre.next = self.chain_mp[val].next
|
||||||
|
if self.tail.val==val:self.tail = self.chain_mp[val].pre
|
||||||
|
if self.head.val==val:self.head = self.chain_mp[val].next
|
||||||
|
del self.chain_mp[val]
|
||||||
|
def incTo(self,key,val):
|
||||||
|
if val not in self.chain_mp:
|
||||||
|
self.addNode(val)
|
||||||
|
self.chain_mp[val][key] = val
|
||||||
|
if val!=1 : # key in the pre node
|
||||||
|
del self.chain_mp[val-1][key]
|
||||||
|
#print(self.chain_mp[val-1])
|
||||||
|
if self.chain_mp[val-1].isEmpty():
|
||||||
|
#print('*'*20)
|
||||||
|
self.delNode(val-1)
|
||||||
|
def decTo(self,key,val):
|
||||||
|
if val not in self.chain_mp:
|
||||||
|
self.addNode(val,dec=True)
|
||||||
|
# notice that the headnode(0) shouldn't add key
|
||||||
|
if val!=0: self.chain_mp[val][key] = val
|
||||||
|
del self.chain_mp[val+1][key]
|
||||||
|
if self.chain_mp[val+1].isEmpty():
|
||||||
|
self.delNode(val+1)
|
||||||
|
|
||||||
|
class AllOne:
|
||||||
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Initialize your data structure here.
|
||||||
|
"""
|
||||||
|
self.op = {"inc":self.inc,"dec":self.dec,"getMaxKey":self.getMaxKey,"getMinKey":self.getMinKey}
|
||||||
|
self.mp = {}
|
||||||
|
self.dll = doubleLinkedList()
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.dll)
|
||||||
|
def __getitem__(self,key):
|
||||||
|
return self.mp[key]
|
||||||
|
def __delitem__(self,key):
|
||||||
|
del self.mp[key]
|
||||||
|
def __setitem__(self,key,val):
|
||||||
|
self.mp[key]= val
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.mp)
|
||||||
|
def inc(self, key,n=1):
|
||||||
|
"""
|
||||||
|
Inserts a new key <Key> with value 1. Or increments an existing key by 1.
|
||||||
|
:type key: str
|
||||||
|
:rtype: void
|
||||||
|
"""
|
||||||
|
if key in self:
|
||||||
|
self[key]+=n
|
||||||
|
else:self[key]=n
|
||||||
|
for i in range(n): self.dll.incTo(key, self[key])
|
||||||
|
def dec(self, key,n=1):
|
||||||
|
"""
|
||||||
|
Decrements an existing key by 1. If Key's value is 1, remove it from the data structure.
|
||||||
|
:type key: str
|
||||||
|
:rtype: void
|
||||||
|
"""
|
||||||
|
if key in self.mp:
|
||||||
|
mn = min( self[key],n)
|
||||||
|
for i in range(mn): self.dll.decTo(key, self[key]-i-1)
|
||||||
|
if self[key] == n:
|
||||||
|
del self[key]
|
||||||
|
else:
|
||||||
|
self[key] = self[key]-n
|
||||||
|
def getMaxKey(self):
|
||||||
|
"""
|
||||||
|
Returns one of the keys with maximal value.
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return self.dll.getMax()
|
||||||
|
|
||||||
|
def getMinKey(self):
|
||||||
|
"""
|
||||||
|
Returns one of the keys with Minimal value.
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return self.dll.getMin()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ops=["inc","inc","inc","inc","inc","dec","dec","getMaxKey","getMinKey"]
|
||||||
|
data=[["a"],["b"],["b"],["b"],["b"],["b"],["b"],[],[]]
|
||||||
|
obj = AllOne()
|
||||||
|
for op,datum in zip(ops,data):
|
||||||
|
print(obj.op[op](*datum))
|
||||||
|
print(op,datum)
|
||||||
|
print(obj)
|
||||||
|
|
||||||
|
'''
|
||||||
|
None
|
||||||
|
inc ['a']
|
||||||
|
min:1, max:1
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
None
|
||||||
|
inc ['b']
|
||||||
|
min:1, max:1
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1, 'b': 1})
|
||||||
|
None
|
||||||
|
inc ['b']
|
||||||
|
min:1, max:2
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(2,{'b': 2})
|
||||||
|
None
|
||||||
|
inc ['b']
|
||||||
|
min:1, max:3
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(3,{'b': 3})
|
||||||
|
None
|
||||||
|
inc ['b']
|
||||||
|
min:1, max:4
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(4,{'b': 4})
|
||||||
|
None
|
||||||
|
dec ['b']
|
||||||
|
min:1, max:3
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(3,{'b': 3})
|
||||||
|
None
|
||||||
|
dec ['b']
|
||||||
|
min:1, max:2
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(2,{'b': 2})
|
||||||
|
b
|
||||||
|
getMaxKey []
|
||||||
|
min:1, max:2
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(2,{'b': 2})
|
||||||
|
a
|
||||||
|
getMinKey []
|
||||||
|
min:1, max:2
|
||||||
|
node(0,{})
|
||||||
|
node(1,{'a': 1})
|
||||||
|
node(2,{'b': 2})
|
||||||
|
'''
|
126
codes/dataStructure/binaryHeap.py
Normal file
126
codes/dataStructure/binaryHeap.py
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
|
||||||
|
from collections import Iterable
|
||||||
|
class node:
|
||||||
|
def __init__(self,val,freq=1):
|
||||||
|
self.val=val
|
||||||
|
self.freq = freq
|
||||||
|
def __eq__(self,a):
|
||||||
|
return self.val == a.val
|
||||||
|
def __lt__(self,a):
|
||||||
|
return self.val<a.val
|
||||||
|
def __le__(self,a):
|
||||||
|
return self.val<=a.val
|
||||||
|
def __gt__(self,a):
|
||||||
|
return self.val>a.val
|
||||||
|
def __ge__(self,a):
|
||||||
|
return self.val>=a.val
|
||||||
|
def __ne__(self,a):
|
||||||
|
return not self == a
|
||||||
|
class binaryHeap:
|
||||||
|
def __init__(self,s=None,sortByFrequency = False,reverse=False):
|
||||||
|
self.sortByFrequency=sortByFrequency
|
||||||
|
self.reverse = reverse
|
||||||
|
self.data = [node(0)] # make index begin with 1
|
||||||
|
if s==None:return
|
||||||
|
if not isinstance(s,Iterable):s = [s]
|
||||||
|
for i in s:
|
||||||
|
self.insert(i)
|
||||||
|
def __bool__(self):
|
||||||
|
return len(self)!=1
|
||||||
|
def _cmp(self,a,b):
|
||||||
|
if self.sortByFrequency:
|
||||||
|
if self.reverse:return a.freq>b.freq
|
||||||
|
else:return a.freq<b.freq
|
||||||
|
else:
|
||||||
|
if self.reverse:return a>b
|
||||||
|
else:return a<b
|
||||||
|
def insert(self,k):
|
||||||
|
if not isinstance(k,node): k = node(k)
|
||||||
|
for j in range(self.data[0].val):
|
||||||
|
i = self.data[j+1]
|
||||||
|
if i==k:
|
||||||
|
i.freq+=1
|
||||||
|
if self.sortByFrequency:
|
||||||
|
idx = self.percolateDown(j+1)
|
||||||
|
self.percolateUp(idx)
|
||||||
|
return
|
||||||
|
self.data.append(k)
|
||||||
|
self.data[0].val += 1
|
||||||
|
self.percolateUp()
|
||||||
|
def percolateUp(self,n=None):
|
||||||
|
if n ==None:n=self.data[0].val
|
||||||
|
tmp = self.data[n]
|
||||||
|
while n!=1 and self._cmp(tmp,self.data[n//2]):
|
||||||
|
self.data[n] = self.data[n//2]
|
||||||
|
n = n//2
|
||||||
|
self.data[n] = tmp
|
||||||
|
def deleteTop(self):
|
||||||
|
tmp = self.data[1]
|
||||||
|
i = self.percolateDown(1)
|
||||||
|
self.data[i] = self.data[-1]
|
||||||
|
self.data[0].val-= 1
|
||||||
|
del self.data[-1]
|
||||||
|
return tmp
|
||||||
|
def percolateDown(self,i):
|
||||||
|
tmp = self.data[i]
|
||||||
|
while self.data[0].val>=2*i+1:
|
||||||
|
if self._cmp(self.data[i*2],self.data[2*i+1]):
|
||||||
|
self.data[i] = self.data[2*i]
|
||||||
|
i = 2*i
|
||||||
|
else:
|
||||||
|
self.data[i] = self.data[2*i+1]
|
||||||
|
i = 2*i+1
|
||||||
|
self.data[i] = tmp
|
||||||
|
return i
|
||||||
|
def __len__(self):
|
||||||
|
return self.data[0].val
|
||||||
|
def Nth(self,n=1):
|
||||||
|
tmp = []
|
||||||
|
for i in range(n):
|
||||||
|
tmp.append(self.deleteTop())
|
||||||
|
for i in tmp:
|
||||||
|
self.insert(i)
|
||||||
|
return tmp[-1]
|
||||||
|
def display(self):
|
||||||
|
val =self.data[0].val+1
|
||||||
|
if self.sortByFrequency:
|
||||||
|
info='heapSort by Frequency:'
|
||||||
|
else:info = 'heapSort by Value:'
|
||||||
|
if self.reverse:
|
||||||
|
info +=' From big to small'
|
||||||
|
else:info +=' From small to big'
|
||||||
|
print('*'*15)
|
||||||
|
print(info)
|
||||||
|
print('total items:%d\nval\tfreq'%(val-1))
|
||||||
|
fmt = '{}\t{}'
|
||||||
|
for i in range(1,val):
|
||||||
|
print(fmt.format(self.data[i].val,self.data[i].freq))
|
||||||
|
print('*'*15)
|
||||||
|
class Test:
|
||||||
|
def topKFrequent(self, words, k):
|
||||||
|
hp = binaryHeap(sortByFrequency = True,reverse=True)
|
||||||
|
for i in words:
|
||||||
|
hp.insert(i)
|
||||||
|
hp.display()
|
||||||
|
n = len(hp)
|
||||||
|
mp = {}
|
||||||
|
while hp:
|
||||||
|
top = hp.deleteTop()
|
||||||
|
if top.freq in mp:
|
||||||
|
mp[top.freq].append(top.val)
|
||||||
|
else:
|
||||||
|
mp[top.freq] = [top.val]
|
||||||
|
for i in mp:
|
||||||
|
mp[i].sort()
|
||||||
|
key = sorted(mp.keys(),reverse = True)
|
||||||
|
rst = []
|
||||||
|
count = 0
|
||||||
|
for i in key:
|
||||||
|
for j in mp[i]:
|
||||||
|
rst.append(j)
|
||||||
|
count+=1
|
||||||
|
if count == k:return rst
|
||||||
|
if __name__ == '__main__':
|
||||||
|
s=["plpaboutit","jnoqzdute","sfvkdqf","mjc","nkpllqzjzp","foqqenbey","ssnanizsav","nkpllqzjzp","sfvkdqf","isnjmy","pnqsz","hhqpvvt","fvvdtpnzx","jkqonvenhx","cyxwlef","hhqpvvt","fvvdtpnzx","plpaboutit","sfvkdqf","mjc","fvvdtpnzx","bwumsj","foqqenbey","isnjmy","nkpllqzjzp","hhqpvvt","foqqenbey","fvvdtpnzx","bwumsj","hhqpvvt","fvvdtpnzx","jkqonvenhx","jnoqzdute","foqqenbey","jnoqzdute","foqqenbey","hhqpvvt","ssnanizsav","mjc","foqqenbey","bwumsj","ssnanizsav","fvvdtpnzx","nkpllqzjzp","jkqonvenhx","hhqpvvt","mjc","isnjmy","bwumsj","pnqsz","hhqpvvt","nkpllqzjzp","jnoqzdute","pnqsz","nkpllqzjzp","jnoqzdute","foqqenbey","nkpllqzjzp","hhqpvvt","fvvdtpnzx","plpaboutit","jnoqzdute","sfvkdqf","fvvdtpnzx","jkqonvenhx","jnoqzdute","nkpllqzjzp","jnoqzdute","fvvdtpnzx","jkqonvenhx","hhqpvvt","isnjmy","jkqonvenhx","ssnanizsav","jnoqzdute","jkqonvenhx","fvvdtpnzx","hhqpvvt","bwumsj","nkpllqzjzp","bwumsj","jkqonvenhx","jnoqzdute","pnqsz","foqqenbey","sfvkdqf","sfvkdqf"]
|
||||||
|
test = Test()
|
||||||
|
print(test.topKFrequent(s,5))
|
46
codes/dataStructure/binaryIndexedTree.cc
Normal file
46
codes/dataStructure/binaryIndexedTree.cc
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
class bit
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
int *p;
|
||||||
|
public:
|
||||||
|
bit(int *,int);
|
||||||
|
~bit();
|
||||||
|
int init(int,int,bool);
|
||||||
|
int getSum(int a,int b){return getSum(a)-getSum(b)};
|
||||||
|
int getSum(int);
|
||||||
|
void update(int,int);
|
||||||
|
};
|
||||||
|
bit::bit(int *a,int j)
|
||||||
|
{
|
||||||
|
p=new int[j+1];
|
||||||
|
n=j;
|
||||||
|
for (int i=0;i<n ;++i )p[i+1]=a[i] ;
|
||||||
|
int i;
|
||||||
|
while(i<n)i*=2;
|
||||||
|
init(1,i,true);
|
||||||
|
}
|
||||||
|
int bit::init(int a,int b,bool isLeft)
|
||||||
|
{
|
||||||
|
if(a==b)return p[k];
|
||||||
|
int l=init(a,(a+b)/2,true);
|
||||||
|
int r=init((a+b)/2+1,b,false);
|
||||||
|
if(isLeft)p[b]=l+r;
|
||||||
|
return p[b];
|
||||||
|
}
|
||||||
|
int bit::getSum(int a)
|
||||||
|
{
|
||||||
|
int rst=0;
|
||||||
|
while(a!=0){
|
||||||
|
rst+=p[a];
|
||||||
|
a-=a&-a;
|
||||||
|
}
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
|
void bit::update(int i , int x)
|
||||||
|
{
|
||||||
|
int delta=x-p[i]
|
||||||
|
while(i<n){
|
||||||
|
p[i] = delta;
|
||||||
|
i+=i&-i;
|
||||||
|
}
|
||||||
|
}
|
72
codes/dataStructure/binaryTree.py
Normal file
72
codes/dataStructure/binaryTree.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
from functools import total_ordering
|
||||||
|
|
||||||
|
@total_ordering
|
||||||
|
class node:
|
||||||
|
def __init__(self,val,left=None,right=None,freq = 1):
|
||||||
|
self.val=val
|
||||||
|
self.left=left
|
||||||
|
self.right=right
|
||||||
|
self.freq = freq
|
||||||
|
def __lt__(self,nd):
|
||||||
|
return self.val<nd.val
|
||||||
|
def __eq__(self,nd):
|
||||||
|
return self.val==nd.val
|
||||||
|
def __repr__(self):
|
||||||
|
return 'node({})'.format(self.val)
|
||||||
|
|
||||||
|
class binaryTree:
|
||||||
|
def __init__(self):
|
||||||
|
self.root=None
|
||||||
|
def add(self,val):
|
||||||
|
def _add(nd,newNode):
|
||||||
|
if nd<newNode:
|
||||||
|
if nd.right is None:nd.right = newNode
|
||||||
|
else:_add(nd.right,newNode)
|
||||||
|
elif nd>newNode:
|
||||||
|
if nd.left is None:nd.left = newNode
|
||||||
|
else : _add(nd.left,newNode)
|
||||||
|
else:nd.freq +=1
|
||||||
|
_add(self.root,node(val))
|
||||||
|
def find(self,val):
|
||||||
|
prt= self._findPrt(self.root,node(val),None)
|
||||||
|
if prt.left and prt.left.val==val:
|
||||||
|
return prt.left
|
||||||
|
elif prt.right and prt.right.val==val:return prt.right
|
||||||
|
else :return None
|
||||||
|
def _findPrt(self,nd,tgt,prt):
|
||||||
|
if nd==tgt or nd is None:return prt
|
||||||
|
elif nd<tgt:return self._findPrt(nd.right,tgt,nd)
|
||||||
|
else:return self._findPrt(nd.left,tgt,nd)
|
||||||
|
def delete(self,val):
|
||||||
|
prt= self._findPrt(self.root,node(val),None)
|
||||||
|
if prt.left and prt.left.val==val:
|
||||||
|
l=prt.left
|
||||||
|
if l.left is None:prt.left = l.right
|
||||||
|
elif l.right is None : prt.left = l.left
|
||||||
|
else:
|
||||||
|
nd = l.left
|
||||||
|
while nd.right is not None:nd = nd.right
|
||||||
|
nd.right = l.right
|
||||||
|
prt.left = l.left
|
||||||
|
elif prt.right and prt.right.val==val:
|
||||||
|
r=prt.right
|
||||||
|
if r.right is None:prt.right = r.right
|
||||||
|
elif r.right is None : prt.right = r.left
|
||||||
|
else:
|
||||||
|
nd = r.left
|
||||||
|
while nd.right is not None:nd = nd.right
|
||||||
|
nd.right = r.right
|
||||||
|
prt.left = r.left
|
||||||
|
|
||||||
|
def preOrder(self):
|
||||||
|
def _p(nd):
|
||||||
|
if nd is not None:
|
||||||
|
print(nd)
|
||||||
|
_p(nd.left)
|
||||||
|
_p(nd.right)
|
||||||
|
_p(self.root)
|
||||||
|
if __name__=="__main__":
|
||||||
|
t = binaryTree()
|
||||||
|
for i in range(10):
|
||||||
|
t.add((i-4)**2)
|
||||||
|
t.preOrder()
|
24
codes/dataStructure/cantor.cc
Normal file
24
codes/dataStructure/cantor.cc
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include<iostream>
|
||||||
|
#include<stdio.h>
|
||||||
|
using namespace std;
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
float f;
|
||||||
|
while(cin.peek()!='E'){
|
||||||
|
cin>>f;
|
||||||
|
getchar();
|
||||||
|
bool flag=true;
|
||||||
|
for(int i=0;i<50&&(f-0.0000001)>0;++i){
|
||||||
|
int t=3*f;
|
||||||
|
f=3*f-t;
|
||||||
|
cout<<f<<endl;
|
||||||
|
if(t==1){
|
||||||
|
cout<<"NON-MEMBER"<<endl;
|
||||||
|
flag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(flag)cout<<"MEMBER"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
208
codes/dataStructure/graph/adjacentList.py
Normal file
208
codes/dataStructure/graph/adjacentList.py
Normal file
|
@ -0,0 +1,208 @@
|
||||||
|
from collections import Iterable,deque
|
||||||
|
class vertex:
|
||||||
|
def __init__(self,mark,firstEdge=None,val=None):
|
||||||
|
self.mark = mark
|
||||||
|
self.val = val
|
||||||
|
self.firstEdge = firstEdge
|
||||||
|
self.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
return 'V'+str(self.mark)
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
class edge:
|
||||||
|
def __init__(self,adjVertexs, weight = 1,nextEdge=None):
|
||||||
|
'''adjVertexs:tuple(v.mark,u.mark)'''
|
||||||
|
self.weight = weight
|
||||||
|
self.adjVertexs = adjVertexs
|
||||||
|
self.nextEdge = nextEdge
|
||||||
|
self.isVisted = False
|
||||||
|
def __add__(self,x):
|
||||||
|
return self.weight +x
|
||||||
|
def __radd__(self,x):
|
||||||
|
return self+x
|
||||||
|
def __getitem__(self,k):
|
||||||
|
if k!=0 or k!=1:raise IndexError
|
||||||
|
return self.adjVertexs[k]
|
||||||
|
def __str__(self):
|
||||||
|
return '--'+str(self.weight)+'--'
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
@property
|
||||||
|
def v(self):
|
||||||
|
return self.adjVertexs[0]
|
||||||
|
@property
|
||||||
|
def u(self):
|
||||||
|
return self.adjVertexs[1]
|
||||||
|
class graph:
|
||||||
|
def __init__(self):
|
||||||
|
self.vertexs = {}
|
||||||
|
self.edges = {}
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.vertexs[i]
|
||||||
|
def __setitem__(selfi,x):
|
||||||
|
self.vertexs[i]= x
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.vertexs)
|
||||||
|
def __bool__(self):
|
||||||
|
return len(self.vertexs)!=0
|
||||||
|
def addVertex(self,vertexs):
|
||||||
|
'''vertexs is a iterable or just a mark that marks the vertex,whichc can be every imutable type'''
|
||||||
|
if not isinstance(vertexs,Iterable):vertexs=[vertexs]
|
||||||
|
for i in vertexs:
|
||||||
|
if not isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i]= vertex(i)
|
||||||
|
if isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i.mark]= i
|
||||||
|
|
||||||
|
def __getVertex(self,v):
|
||||||
|
if not isinstance(v,vertex):
|
||||||
|
if v not in self.vertexs:
|
||||||
|
self.vertexs[v]=vertex(v)
|
||||||
|
return self.vertexs[v]
|
||||||
|
return v
|
||||||
|
def addEdge(self,v,u,weight = 1):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
arc = self.findEdge(v,u)
|
||||||
|
if arc!=None:return #examine that if v,u have been already connected
|
||||||
|
vertexs = (v,u)
|
||||||
|
newEdge = edge (vertexs,weight)
|
||||||
|
self.edges[vertexs] = newEdge
|
||||||
|
if v.firstEdge==None:
|
||||||
|
v.firstEdge=newEdge
|
||||||
|
else:
|
||||||
|
arc=v.firstEdge.nextEdge
|
||||||
|
v.firstEdge=newEdge
|
||||||
|
def findEdge(self,v,u):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
arc = v.firstEdge
|
||||||
|
while arc!=None and u not in arc:
|
||||||
|
arc = arc.nextEdge
|
||||||
|
if arc!=None:return arc
|
||||||
|
arc = u.firstEdge
|
||||||
|
while arc!=None and v not in arc:
|
||||||
|
arc = arc.nextEdge
|
||||||
|
return arc
|
||||||
|
def delEdge(self,v,u):
|
||||||
|
if not isinstance(v,vertex):v= self.vertexs[v]
|
||||||
|
if not isinstance(u,vertex):u= self.vertexs[u]
|
||||||
|
if u in v.firstEdge:
|
||||||
|
v.firstEdge =v.firstEdge.nextEdge
|
||||||
|
else:
|
||||||
|
arc = v.firstEdge
|
||||||
|
while arc.nextEdge!=e:
|
||||||
|
arc = arc.nextEdge
|
||||||
|
if arc!=None: arc.nextEdge = arc.nextEdge.nextEdge
|
||||||
|
else:
|
||||||
|
if v in u.firstEdge:
|
||||||
|
u.firstEdge =u.firstEdge.nextEdge
|
||||||
|
else:
|
||||||
|
arc = u.firstEdge
|
||||||
|
while arc.nextEdge!=e:
|
||||||
|
arc = arc.nextEdge
|
||||||
|
arc.nextEdge = arc.nextEdge.nextEdge
|
||||||
|
del self.edges[(v,u)]
|
||||||
|
def revisit(self):
|
||||||
|
for i in self.vertexs.values():
|
||||||
|
i.isVisited = False
|
||||||
|
for i in self.edges.values():
|
||||||
|
i.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
arcs= list(self.edges.keys())
|
||||||
|
arcs=[str(i[0])+str(self.edges[i])+str(i[1]) for i in arcs]
|
||||||
|
s= '\n'.join(arcs)
|
||||||
|
return s
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
def minPath(self,v,u):
|
||||||
|
if v not in self or u not in self:return -1
|
||||||
|
v=self.__getVertex(v)
|
||||||
|
u=self.__getVertex(u)
|
||||||
|
q=deque([v])
|
||||||
|
last={i:None for i in self.vertexs.values()}
|
||||||
|
last[v] = 0
|
||||||
|
ds={i:1000000 for i in self.vertexs.values()}
|
||||||
|
ds[v]=0
|
||||||
|
while len(q)!=0:
|
||||||
|
nd = q.popleft()
|
||||||
|
nd.isVisited=True
|
||||||
|
arc = nd.firstEdge
|
||||||
|
while arc!=None:
|
||||||
|
tgt=None
|
||||||
|
if arc.v==nd:
|
||||||
|
tgt = arc.u
|
||||||
|
else:tgt = arc.v
|
||||||
|
tmp=ds[nd]+arc
|
||||||
|
if ds[tgt] >tmp:
|
||||||
|
ds[tgt]=tmp
|
||||||
|
last[tgt] = nd
|
||||||
|
if not tgt.isVisited:q.append(tgt)
|
||||||
|
'''
|
||||||
|
cur = u
|
||||||
|
while cur !=v:
|
||||||
|
print(str(cur)+'<---',end='')
|
||||||
|
cur =last[cur]
|
||||||
|
print(str(v))
|
||||||
|
'''
|
||||||
|
return ds[u]
|
||||||
|
def hasCircle(self):
|
||||||
|
pass
|
||||||
|
def display(self):
|
||||||
|
print('vertexs')
|
||||||
|
for i in self.vertexs:
|
||||||
|
print(i)
|
||||||
|
print('edges')
|
||||||
|
for i in self.edges:
|
||||||
|
arc=self.edges[i]
|
||||||
|
print(str(arc.v)+str(arc)+str(arc.u))
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
n=int(input())
|
||||||
|
while n>0:
|
||||||
|
cities=int(input())
|
||||||
|
n-=1
|
||||||
|
g=graph()
|
||||||
|
li={}
|
||||||
|
for i in range(cities):
|
||||||
|
li[input()]=i+1
|
||||||
|
arc=int(input())
|
||||||
|
for j in range(arc):
|
||||||
|
s=input().split(' ')
|
||||||
|
g.addEdge(i+1,int(s[0]),int(s[1]))
|
||||||
|
ct =int(input())
|
||||||
|
for i in range(ct):
|
||||||
|
line = input()
|
||||||
|
line= line .split(' ')
|
||||||
|
v,u = li[line[0]],li[line[1]]
|
||||||
|
print(g.minPath(v,u))
|
||||||
|
g.revisit()
|
||||||
|
#http://www.spoj.com/submit/SHPATH/id=20525991
|
||||||
|
'''
|
||||||
|
1
|
||||||
|
4
|
||||||
|
gdansk
|
||||||
|
2
|
||||||
|
2 1
|
||||||
|
3 3
|
||||||
|
bydgoszcz
|
||||||
|
3
|
||||||
|
1 1
|
||||||
|
3 1
|
||||||
|
4 4
|
||||||
|
torun
|
||||||
|
3
|
||||||
|
1 3
|
||||||
|
2 1
|
||||||
|
4 1
|
||||||
|
warszawa
|
||||||
|
2
|
||||||
|
2 4
|
||||||
|
3 1
|
||||||
|
2
|
||||||
|
gdansk warszawa
|
||||||
|
bydgoszcz warszawa
|
||||||
|
V4<---V3<---V2<---V1
|
||||||
|
3
|
||||||
|
V4<---V3<---V2
|
||||||
|
2
|
||||||
|
>>>
|
||||||
|
'''
|
236
codes/dataStructure/graph/directed.py
Normal file
236
codes/dataStructure/graph/directed.py
Normal file
|
@ -0,0 +1,236 @@
|
||||||
|
from collections import Iterable,deque
|
||||||
|
class vertex:
|
||||||
|
def __init__(self,mark,val=None ,firstEdge = None):
|
||||||
|
self.mark = mark
|
||||||
|
self.val = val
|
||||||
|
self.firstEdge = firstEdge
|
||||||
|
self.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
if '0'<=self.mark[0]<='9':return 'v'+str(self.mark)
|
||||||
|
return str(self.mark)
|
||||||
|
def __repr__(self):
|
||||||
|
li=[]
|
||||||
|
arc= self.firstEdge
|
||||||
|
while arc!=None:
|
||||||
|
li.append(arc)
|
||||||
|
arc= arc.outNextEdge
|
||||||
|
return str(self)+ ' to:'+str([str(i.inArrow) for i in li])
|
||||||
|
class edge:
|
||||||
|
def __init__(self,outArrow,inArrow,outNextEdge = None,inNextEdge = None, weight = 1):
|
||||||
|
self.weight = weight
|
||||||
|
self.inNextEdge = inNextEdge
|
||||||
|
self.outNextEdge = outNextEdge
|
||||||
|
self.outArrow = outArrow
|
||||||
|
self.inArrow=inArrow
|
||||||
|
self.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
return '--'+str(self.weight)+'-->'
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
class graph:
|
||||||
|
def __init__(self):
|
||||||
|
self.vertexs = {}
|
||||||
|
self.edges = {}
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.vertexs[i]
|
||||||
|
def __setitem__(selfi,x):
|
||||||
|
self.vertexs[i]= x
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.vertexs.values())
|
||||||
|
def __bool__(self):
|
||||||
|
return len(self.vertexs)!=0
|
||||||
|
def addVertex(self,vertexs):
|
||||||
|
'''vertexs is a iterable or just a mark that marks the vertex,whichc can be every imutable type'''
|
||||||
|
if not isinstance(vertexs,Iterable):vertexs=[vertexs]
|
||||||
|
for i in vertexs:
|
||||||
|
if not isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i]= vertex(i)
|
||||||
|
if isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i.mark]= i
|
||||||
|
def isConnected(self,v,u):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
arc= v.firstEdge
|
||||||
|
while arc!=None:
|
||||||
|
if arc.inArrow==u:return True
|
||||||
|
arc = arc.inNextEdge
|
||||||
|
return False
|
||||||
|
def __getVertex(self,v):
|
||||||
|
if not isinstance(v,vertex):
|
||||||
|
if v not in self.vertexs:
|
||||||
|
self.vertexs[v]=vertex(v)
|
||||||
|
return self.vertexs[v]
|
||||||
|
return v
|
||||||
|
def addEdge(self,v,u,weight = 1):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
arc = v.firstEdge
|
||||||
|
while arc!=None: #examine that if v,u have been already connected
|
||||||
|
if arc.inArrow==u: return
|
||||||
|
arc= arc.outNextEdge
|
||||||
|
newEdge = edge(v,u,v.firstEdge,u.firstEdge,weight)
|
||||||
|
self.edges[(v.mark,u.mark)] = newEdge
|
||||||
|
v.firstEdge = newEdge
|
||||||
|
def delEdge(self,v,u):
|
||||||
|
if not isinstance(v,vertex):v= self.vertexs[v]
|
||||||
|
if not isinstance(u,vertex):u= self.vertexs[u]
|
||||||
|
self._unrelated(v,u)
|
||||||
|
del self.edges[(v.mark,u.mark)]
|
||||||
|
def _unrelated(self,v,u):
|
||||||
|
if v.firstEdge==None:return
|
||||||
|
if v.firstEdge.inArrow == u:
|
||||||
|
v.firstEdge =v.firstEdge.outNextEdge
|
||||||
|
else:
|
||||||
|
arc = v.firstEdge
|
||||||
|
while arc.outNextEdge!=None:
|
||||||
|
if arc.outNextEdge.inArrow ==u:
|
||||||
|
arc.outNextEdge = arc.outNextEdge.outNextEdge
|
||||||
|
break
|
||||||
|
def revisit(self):
|
||||||
|
for i in self.vertexs:
|
||||||
|
self.vertexs[i].isVisited=False
|
||||||
|
for i in self.edges:
|
||||||
|
self.edges[i].isVisited=False
|
||||||
|
def __str__(self):
|
||||||
|
arcs= list(self.edges.keys())
|
||||||
|
arcs=[str(i[0])+'--->'+str(i[1])+' weight:'+str(self.edges[i].weight) for i in arcs]
|
||||||
|
s= '\n'.join(arcs)
|
||||||
|
return s
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
def notIn(self,v):
|
||||||
|
if (isinstance(v,vertex) and v.mark not in self.vertexs) or v not in self.vertexs:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
def visitPath(self,v,u):
|
||||||
|
'''bfs'''
|
||||||
|
if self.notIn(v) or self.notIn(u):
|
||||||
|
return None,None
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
if v.firstEdge==None:return None,None
|
||||||
|
q=deque([v.firstEdge])
|
||||||
|
isFind=False
|
||||||
|
vs,es=[],[]
|
||||||
|
while len(q)!=0:
|
||||||
|
vs,es=[],[]
|
||||||
|
arc= q.popleft()
|
||||||
|
if arc.outNextEdge!=None and not arc.outNextEdge.isVisited:q.append(arc.outNextEdge)
|
||||||
|
while arc!=None:
|
||||||
|
if arc.isVisited:break
|
||||||
|
arc.isVisited=True
|
||||||
|
es.append(arc)
|
||||||
|
vs.append(arc.inArrow)
|
||||||
|
arc.outArrow.isVisited=True
|
||||||
|
if arc.inArrow==u:
|
||||||
|
isFind=True
|
||||||
|
break
|
||||||
|
arc = arc.inArrow.firstEdge
|
||||||
|
# very important , avoid circle travel
|
||||||
|
while arc.inArrow.isVisited and arc.outNextEdge:arc = arc.outNextEdge
|
||||||
|
if isFind:break
|
||||||
|
else:return None,None
|
||||||
|
'''
|
||||||
|
se = [str(i) for i in es]
|
||||||
|
sv = [str(i) for i in vs]
|
||||||
|
print(str(v),end='')
|
||||||
|
for i,j in zip(se,sv):
|
||||||
|
print(i,j,end='')
|
||||||
|
'''
|
||||||
|
return vs,es
|
||||||
|
def hasVertex(self,mark):
|
||||||
|
return mark in self.vertexs
|
||||||
|
def display(self):
|
||||||
|
print('vertexs')
|
||||||
|
for i in self.vertexs:
|
||||||
|
print(self.vertexs[i].__repr__())
|
||||||
|
print('edges')
|
||||||
|
for i in self.edges:
|
||||||
|
arc=self.edges[i]
|
||||||
|
print(str(arc.outArrow)+str(arc)+str(arc.inArrow))
|
||||||
|
|
||||||
|
class Solution(object):
|
||||||
|
def calcEquation(self, equations, values, queries):
|
||||||
|
"""
|
||||||
|
:type equations: List[List[str]]
|
||||||
|
:type values: List[float]
|
||||||
|
:type queries: List[List[str]]
|
||||||
|
:rtype: List[float]
|
||||||
|
"""
|
||||||
|
rst =[]
|
||||||
|
g= graph()
|
||||||
|
for edge,wt in zip(equations,values):
|
||||||
|
g.addEdge(edge[0],edge[1],wt)
|
||||||
|
g.addEdge(edge[1],edge[0],1/wt)###### to serach quickly but sacrifacing some space
|
||||||
|
g.display()
|
||||||
|
for i in queries:
|
||||||
|
if i[0]==i[1]:
|
||||||
|
if i[0] in g.vertexs:rst.append(1.0)
|
||||||
|
else:rst.append(-1.0)
|
||||||
|
continue
|
||||||
|
_,path = g.visitPath(i[0],i[1])
|
||||||
|
if path==None:
|
||||||
|
if not path:rst.append(-1.0)
|
||||||
|
else:
|
||||||
|
mul = 1
|
||||||
|
for i in path:mul*=i.weight
|
||||||
|
rst.append(mul)
|
||||||
|
g.revisit()
|
||||||
|
return rst
|
||||||
|
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
equations = [["a","b"],["e","f"],["b","e"]]
|
||||||
|
values = [3.4,1.4,2.3]
|
||||||
|
queries = [["b","a"],["a","f"],["f","f"],["e","e"],["c","c"],["a","c"],["f","e"]]
|
||||||
|
sol = Solution()
|
||||||
|
ret=sol.calcEquation( equations, values, queries)
|
||||||
|
print(ret)
|
||||||
|
|
||||||
|
'''
|
||||||
|
[0.29411764705882354, 10.947999999999999, 1.0, 1.0, -1.0, -1.0, 0.7142857142857143]
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
equations = [ ["a", "b"], ["b", "c"] ]
|
||||||
|
values = [2.0, 3.0]
|
||||||
|
queries = [ ["a", "c"], ["b", "a"], ["a", "e"], ["a", "a"], ["x", "x"] ]
|
||||||
|
sol = Solution()
|
||||||
|
ret=sol.calcEquation( equations, values, queries)
|
||||||
|
print(ret)
|
||||||
|
'''
|
||||||
|
|
||||||
|
'''
|
||||||
|
[6.0, 0.5, -1.0, -1.0, -1.0]
|
||||||
|
'''
|
||||||
|
|
||||||
|
'''
|
||||||
|
g = graph()
|
||||||
|
g.addEdge(1,2)
|
||||||
|
g.addEdge(2,1)
|
||||||
|
g.addEdge(3,1)
|
||||||
|
g.addEdge(1,4)
|
||||||
|
g.addEdge(3,2)
|
||||||
|
g.addEdge(2,4)
|
||||||
|
g.addVertex(6)
|
||||||
|
g.addEdge(4,6)
|
||||||
|
g.delEdge(1,2)
|
||||||
|
g.display()
|
||||||
|
g.visitPath(3,6)
|
||||||
|
|
||||||
|
'''
|
||||||
|
'''
|
||||||
|
vertexs
|
||||||
|
v1 to:['v4']
|
||||||
|
v2 to:['v4', 'v1']
|
||||||
|
v3 to:['v2', 'v1']
|
||||||
|
v4 to:['v6']
|
||||||
|
v6 to:[]
|
||||||
|
edges
|
||||||
|
v2--1-->v1
|
||||||
|
v3--1-->v1
|
||||||
|
v1--1-->v4
|
||||||
|
v3--1-->v2
|
||||||
|
v2--1-->v4
|
||||||
|
v4--1-->v6
|
||||||
|
>>>
|
||||||
|
'''
|
173
codes/dataStructure/graph/graph.cc
Normal file
173
codes/dataStructure/graph/graph.cc
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
#include<iostream>
|
||||||
|
#include<vector>
|
||||||
|
#include<algorithm>
|
||||||
|
#include<list>
|
||||||
|
bool LOG=false;
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class edge;
|
||||||
|
class vertex
|
||||||
|
{
|
||||||
|
friend ostream &operator<<(ostream&,const vertex *);
|
||||||
|
friend ostream &operator<<(ostream&,const edge *);
|
||||||
|
friend class graph;
|
||||||
|
friend class edge;
|
||||||
|
public:
|
||||||
|
vertex(int n,edge* arc = NULL):val(n),firstEdge(arc){isVisited=false;}
|
||||||
|
~vertex(){if(LOG)cout<<"V"<<val+1<<" is dead "<<endl;}
|
||||||
|
private:
|
||||||
|
bool isVisited;
|
||||||
|
int val ;
|
||||||
|
edge* firstEdge;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class edge
|
||||||
|
{
|
||||||
|
friend ostream &operator<<(ostream&,const edge *);
|
||||||
|
friend ostream &operator<<(ostream&,const vertex *);
|
||||||
|
friend class graph;
|
||||||
|
friend class vertex;
|
||||||
|
public:
|
||||||
|
edge(vertex * vo,vertex *vi,int w=1,edge *next=NULL):\
|
||||||
|
out(vo),in(vi),weight(w),nextEdge(next){isVisited=false;}
|
||||||
|
~edge(){}
|
||||||
|
private:
|
||||||
|
bool isVisited;
|
||||||
|
int weight;
|
||||||
|
vertex * in,*out;
|
||||||
|
edge* nextEdge;
|
||||||
|
};
|
||||||
|
class graph
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int vNum,eNum;
|
||||||
|
vector<vertex*> vs;
|
||||||
|
vector<edge*> es;
|
||||||
|
bool weighted;
|
||||||
|
bool directed;
|
||||||
|
public:
|
||||||
|
graph():vNum(0),eNum(0),weighted(false),directed(false){}
|
||||||
|
graph(int ,int,bool,bool);
|
||||||
|
~graph();
|
||||||
|
void getData();
|
||||||
|
void display();
|
||||||
|
int minPath(int , int );
|
||||||
|
void reVisitVertex(){for (int i=0;i<vNum ;vs[i++]->isVisited=false ) ;}
|
||||||
|
void reVisitEdge(){for (int i=0;i<eNum ;es[i++]->isVisited=false ) ;}
|
||||||
|
};
|
||||||
|
graph::graph(int n,int m,bool weighted,bool directed)\
|
||||||
|
:vNum(n),eNum(m),weighted(weighted),directed(directed)
|
||||||
|
{
|
||||||
|
cin.ignore(1);
|
||||||
|
for (int i=0;i<vNum ;++i ) vs.push_back(new vertex(i)) ;
|
||||||
|
int a,b,w=1;
|
||||||
|
for (int i=0;i<eNum ;++i ){
|
||||||
|
cin >>a >>b;
|
||||||
|
--a,--b;
|
||||||
|
if(weighted)cin>>w;
|
||||||
|
edge *arc=new edge (vs[a],vs[b],w,vs[a]->firstEdge);
|
||||||
|
vs[a]->firstEdge = arc;
|
||||||
|
es.push_back(arc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ostream& operator<<(ostream& os,const vertex* v)
|
||||||
|
{
|
||||||
|
os<<"V"<<v->val+1<<" -->";
|
||||||
|
edge *arc= v->firstEdge;
|
||||||
|
while(arc){
|
||||||
|
os<<" V"<<arc->in->val+1;
|
||||||
|
arc=arc->nextEdge;
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
ostream& operator<<(ostream& os,const edge* e)
|
||||||
|
{
|
||||||
|
os<<"V"<<e->out->val+1<<"--"<<e->weight<<"-->"<<e->in->val+1;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
graph::~graph()
|
||||||
|
{
|
||||||
|
for (int i=0;i<vNum ;++i ){
|
||||||
|
edge *arc = vs[i]->firstEdge;
|
||||||
|
while(arc){
|
||||||
|
edge *p=arc;
|
||||||
|
arc=arc->nextEdge;
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
delete vs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void graph::display()
|
||||||
|
{
|
||||||
|
cout<<"-----VERTEXS-----"<<endl;
|
||||||
|
for(int i = 0;i<vs.size();cout<<vs[i]<<endl,++i);
|
||||||
|
cout<<"------EDGES------"<<endl;
|
||||||
|
for (int i=0;i<eNum ;cout<<es[i]<<endl,++i ) ;
|
||||||
|
}
|
||||||
|
int graph::minPath(int v,int u)
|
||||||
|
{
|
||||||
|
vertex *p= vs[v-1],*q= vs[u-1];
|
||||||
|
vector<vertex*> last; // can't initialize with n NULL ptr
|
||||||
|
for (int i=0;i<vNum ;last.push_back(NULL),++i ) ;
|
||||||
|
vector<int> distnace(vNum,-1);
|
||||||
|
distnace[p->val] = 0;
|
||||||
|
list<vertex*> que;
|
||||||
|
que.push_back(p);
|
||||||
|
while(!que.empty()){
|
||||||
|
vertex * cur = que.front();
|
||||||
|
que.pop_front();
|
||||||
|
cur->isVisited = true;
|
||||||
|
edge *arc = cur->firstEdge;
|
||||||
|
while(arc){
|
||||||
|
vertex * tmp=arc->in;
|
||||||
|
if(! tmp->isVisited){
|
||||||
|
que.push_back(tmp);
|
||||||
|
int sum = arc->weight+distnace[arc->out->val];
|
||||||
|
if(distnace[tmp->val]==-1){
|
||||||
|
distnace[tmp->val]= sum;
|
||||||
|
last[tmp->val] = arc->out;
|
||||||
|
}
|
||||||
|
else if(distnace[tmp->val]>sum){
|
||||||
|
distnace[tmp->val] = sum;
|
||||||
|
last[tmp->val] = arc->out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arc = arc->nextEdge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<"path V"<<v<<" to V"<<u<<"\n";
|
||||||
|
vertex *cur = q;
|
||||||
|
while(cur&& last[cur->val]!=p ){
|
||||||
|
cout<<"V"<<cur->val+1<<"<--";
|
||||||
|
cur = last[cur->val];
|
||||||
|
}
|
||||||
|
reVisitVertex();
|
||||||
|
if(! cur) {
|
||||||
|
cout.clear();
|
||||||
|
cout<<"there isn't path from V"<<v<<" to V"<<u<<endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
return distnace[u-1];
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int n,m ;
|
||||||
|
bool weighted,directed;
|
||||||
|
cout<<"weighted ? [y/N] :";
|
||||||
|
if(cin.get()=='y') weighted = true;
|
||||||
|
else weighted=false;
|
||||||
|
cin.ignore(1);
|
||||||
|
cout<<"directed ? [y/N] :";
|
||||||
|
if(cin.get()=='y') directed= true;
|
||||||
|
else directed= false;
|
||||||
|
cout<<"input vertex num and edge num"<<endl;
|
||||||
|
cin>>n>>m;
|
||||||
|
graph g=graph(n,m,weighted,directed);
|
||||||
|
g.display();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
BIN
codes/dataStructure/graph/graph.exe
Normal file
BIN
codes/dataStructure/graph/graph.exe
Normal file
Binary file not shown.
BIN
codes/dataStructure/graph/graph.o
Normal file
BIN
codes/dataStructure/graph/graph.o
Normal file
Binary file not shown.
186
codes/dataStructure/graph/undirected.py
Normal file
186
codes/dataStructure/graph/undirected.py
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
from collections import Iterable,deque
|
||||||
|
class vertex:
|
||||||
|
def __init__(self,mark,val=None):
|
||||||
|
self.mark = mark
|
||||||
|
self.val = val
|
||||||
|
self.edges = {}
|
||||||
|
self.isVisited = False
|
||||||
|
def __getitem__(self,adjVertexMark):
|
||||||
|
return self.edges[adjVertexMark]
|
||||||
|
def __delitem__(self,k):
|
||||||
|
del self.edges[k]
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.edges.values())
|
||||||
|
def __str__(self):
|
||||||
|
return 'V'+str(self.mark)
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
class edge:
|
||||||
|
def __init__(self,adjVertexs, weight = 1):
|
||||||
|
'''adjVertexs:tuple(v.mark,u.mark)'''
|
||||||
|
self.weight = weight
|
||||||
|
self.adjVertexs = adjVertexs
|
||||||
|
self.isVisted = False
|
||||||
|
def __add__(self,x):
|
||||||
|
return self.weight +x
|
||||||
|
def __radd__(self,x):
|
||||||
|
return self+x
|
||||||
|
def __getitem__(self,k):
|
||||||
|
if k!=0 or k!=1:raise IndexError
|
||||||
|
return self.adjVertexs[k]
|
||||||
|
def __str__(self):
|
||||||
|
return '--'+str(self.weight)+'--'
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
@property
|
||||||
|
def v(self):
|
||||||
|
return self.adjVertexs[0]
|
||||||
|
@property
|
||||||
|
def u(self):
|
||||||
|
return self.adjVertexs[1]
|
||||||
|
class graph:
|
||||||
|
def __init__(self):
|
||||||
|
self.vertexs = {}
|
||||||
|
self.edges = {}
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.vertexs[i]
|
||||||
|
def __setitem__(selfi,x):
|
||||||
|
self.vertexs[i]= x
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.vertexs)
|
||||||
|
def __bool__(self):
|
||||||
|
return len(self.vertexs)!=0
|
||||||
|
def addVertex(self,vertexs):
|
||||||
|
'''vertexs is a iterable or just a mark that marks the vertex,whichc can be every imutable type'''
|
||||||
|
if not isinstance(vertexs,Iterable):vertexs=[vertexs]
|
||||||
|
for i in vertexs:
|
||||||
|
if not isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i]= vertex(i)
|
||||||
|
if isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i.mark]= i
|
||||||
|
|
||||||
|
def __getVertex(self,v):
|
||||||
|
if not isinstance(v,vertex):
|
||||||
|
if v not in self.vertexs:
|
||||||
|
self.vertexs[v]=vertex(v)
|
||||||
|
return self.vertexs[v]
|
||||||
|
return v
|
||||||
|
def addEdge(self,v,u,weight = 1):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
for arc in v:
|
||||||
|
if u in arc.adjVertexs:return #examine that if v,u have been already connected
|
||||||
|
vertexs = (v,u)
|
||||||
|
newEdge = edge (vertexs,weight)
|
||||||
|
self.edges[vertexs] = newEdge
|
||||||
|
v.edges[u] = newEdge
|
||||||
|
u.edges[v] = newEdge
|
||||||
|
def delEdge(self,v,u):
|
||||||
|
if not isinstance(v,vertex):v= self.vertexs[v]
|
||||||
|
if not isinstance(u,vertex):u= self.vertexs[u]
|
||||||
|
try:
|
||||||
|
del v[u]
|
||||||
|
del u[v]
|
||||||
|
except:print("error!"+str(v)+','+str(u)+' arent adjacent now')
|
||||||
|
del self.edges[(v,u)]
|
||||||
|
def revisit(self):
|
||||||
|
for i in self.vertexs.values():
|
||||||
|
i.isVisited = False
|
||||||
|
for i in self.edges.values():
|
||||||
|
i.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
arcs= list(self.edges.keys())
|
||||||
|
arcs=[str(i[0])+str(self.edges[i])+str(i[1]) for i in arcs]
|
||||||
|
s= '\n'.join(arcs)
|
||||||
|
return s
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
def minPath(self,v,u):
|
||||||
|
v=self.__getVertex(v)
|
||||||
|
u=self.__getVertex(u)
|
||||||
|
q=deque([v])
|
||||||
|
last={i:None for i in self.vertexs.values()}
|
||||||
|
last[v] = 0
|
||||||
|
ds={i:1000000 for i in self.vertexs.values()}
|
||||||
|
ds[v]=0
|
||||||
|
while len(q)!=0:
|
||||||
|
nd = q.popleft()
|
||||||
|
nd.isVisited=True
|
||||||
|
for edge in nd:
|
||||||
|
tgt=None
|
||||||
|
if edge.v==nd:
|
||||||
|
tgt = edge.u
|
||||||
|
else:tgt = edge.v
|
||||||
|
tmp=ds[nd]+edge
|
||||||
|
if ds[tgt] >tmp:
|
||||||
|
ds[tgt]=tmp
|
||||||
|
last[tgt] = nd
|
||||||
|
if not tgt.isVisited:q.append(tgt)
|
||||||
|
'''
|
||||||
|
cur = u
|
||||||
|
while cur !=v:
|
||||||
|
print(str(cur)+'<---',end='')
|
||||||
|
cur =last[cur]
|
||||||
|
print(str(v))
|
||||||
|
'''
|
||||||
|
return ds[u]
|
||||||
|
def hasCircle(self):
|
||||||
|
pass
|
||||||
|
def display(self):
|
||||||
|
print('vertexs')
|
||||||
|
for i in self.vertexs:
|
||||||
|
print(i)
|
||||||
|
print('edges')
|
||||||
|
for i in self.edges:
|
||||||
|
arc=self.edges[i]
|
||||||
|
print(str(arc.v)+str(arc)+str(arc.u))
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
n=int(input())
|
||||||
|
while n>0:
|
||||||
|
cities=int(input())
|
||||||
|
n-=1
|
||||||
|
g=graph()
|
||||||
|
li={}
|
||||||
|
for i in range(cities):
|
||||||
|
li[input()]=i+1
|
||||||
|
arc=int(input())
|
||||||
|
for j in range(arc):
|
||||||
|
s=input().split(' ')
|
||||||
|
g.addEdge(i+1,int(s[0]),int(s[1]))
|
||||||
|
ct =int(input())
|
||||||
|
for i in range(ct):
|
||||||
|
line = input()
|
||||||
|
line= line .split(' ')
|
||||||
|
v,u = li[line[0]],li[line[1]]
|
||||||
|
print(g.minPath(v,u))
|
||||||
|
g.revisit()
|
||||||
|
#http://www.spoj.com/submit/SHPATH/id=20525991
|
||||||
|
'''
|
||||||
|
1
|
||||||
|
4
|
||||||
|
gdansk
|
||||||
|
2
|
||||||
|
2 1
|
||||||
|
3 3
|
||||||
|
bydgoszcz
|
||||||
|
3
|
||||||
|
1 1
|
||||||
|
3 1
|
||||||
|
4 4
|
||||||
|
torun
|
||||||
|
3
|
||||||
|
1 3
|
||||||
|
2 1
|
||||||
|
4 1
|
||||||
|
warszawa
|
||||||
|
2
|
||||||
|
2 4
|
||||||
|
3 1
|
||||||
|
2
|
||||||
|
gdansk warszawa
|
||||||
|
bydgoszcz warszawa
|
||||||
|
V4<---V3<---V2<---V1
|
||||||
|
3
|
||||||
|
V4<---V3<---V2
|
||||||
|
2
|
||||||
|
>>>
|
||||||
|
'''
|
364
codes/dataStructure/huffman.cc
Normal file
364
codes/dataStructure/huffman.cc
Normal file
|
@ -0,0 +1,364 @@
|
||||||
|
#include<math.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<direct.h>
|
||||||
|
#include<iostream>
|
||||||
|
#include<algorithm>
|
||||||
|
#include<map>
|
||||||
|
#include<windows.h>
|
||||||
|
#include<iomanip>
|
||||||
|
#include<string>
|
||||||
|
#include<vector>
|
||||||
|
#include<queue>
|
||||||
|
#define numDigit 10
|
||||||
|
#define nameLength 50
|
||||||
|
#define starNum 80
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void cat(string s)
|
||||||
|
{
|
||||||
|
FILE* f=fopen(s.c_str(),"rb");
|
||||||
|
cout<<"file content"<<endl;
|
||||||
|
while(!feof(f)){
|
||||||
|
cout<<fgetc(f);
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
}
|
||||||
|
string uniFileName(string file)
|
||||||
|
{
|
||||||
|
FILE * check = fopen(file.c_str(),"rb");
|
||||||
|
if(check){
|
||||||
|
char c;
|
||||||
|
cout<<"the file "<<file<<" already exists! continue? [Y/n]:"<<flush;
|
||||||
|
c=cin.get();
|
||||||
|
if(c=='n')exit(0);
|
||||||
|
int p,q;
|
||||||
|
p= file.find('(');
|
||||||
|
q=file.rfind('.');
|
||||||
|
if(q==string::npos)q=file.size();
|
||||||
|
if(p==string::npos)p=q;
|
||||||
|
string name=file.substr(0,p),suffix=file.substr(q,file.size());
|
||||||
|
int n=0;
|
||||||
|
while(true){
|
||||||
|
char s[3];
|
||||||
|
n+=1;
|
||||||
|
itoa(n,s,10);
|
||||||
|
file=(name+"("+s+")"+suffix);
|
||||||
|
FILE* f=fopen(file.c_str(),"rb");
|
||||||
|
if(!f)break;
|
||||||
|
else fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
template<class t1, class t2>
|
||||||
|
void mapprint(map<t1,t2> &f)
|
||||||
|
{
|
||||||
|
for(class map<t1,t2>::iterator i = f.begin();i!=f.end();++i)
|
||||||
|
cout<<i->first<<") : "<<i->second<<endl;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
class node
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ky key;
|
||||||
|
wt val;
|
||||||
|
bool visited;
|
||||||
|
node * left,*right;
|
||||||
|
node(const node &a){val = a.val;key= a.key;visited = a.visited;left= a.left;right=a.right;}
|
||||||
|
node(ky k=0,wt v=0):key(k),val(v),visited(false),left(NULL),right(NULL){};
|
||||||
|
bool operator<(const node<ky,wt> & a)const{return val>a.val;};
|
||||||
|
};
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
class huffman
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
node<ky,wt> root;
|
||||||
|
string res;
|
||||||
|
public:
|
||||||
|
long total(){return root.val;}
|
||||||
|
map<ky,string> encode_map;
|
||||||
|
map<string,ky> decode_map;
|
||||||
|
huffman(map<ky,wt>& mp);
|
||||||
|
void display();
|
||||||
|
string encode(string,long &);
|
||||||
|
string decode(string,long&);
|
||||||
|
void preOrder(node<ky,wt>*,string);
|
||||||
|
};
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
huffman<ky,wt>::huffman(map<ky,wt>& mp)
|
||||||
|
{
|
||||||
|
if(mp.empty()){
|
||||||
|
cout<<"Error! No data!"<<endl;
|
||||||
|
root=NULL;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
priority_queue<node<ky,wt> > hp;
|
||||||
|
for(typename map<ky,wt>::iterator i=mp.begin();i!=mp.end();++i){
|
||||||
|
hp.push( node<ky,wt>(i->first,i->second));
|
||||||
|
}
|
||||||
|
int n =hp.size();
|
||||||
|
if(n==1){
|
||||||
|
root = hp.top();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while(--n>=1){
|
||||||
|
node<ky,wt> *a = new node<ky,wt>(hp.top());
|
||||||
|
hp.pop();
|
||||||
|
node<ky,wt> *b = new node<ky,wt>(hp.top());
|
||||||
|
hp.pop();
|
||||||
|
node<ky,wt> * tmp = new node<ky,wt>(0,a->val+b->val);
|
||||||
|
tmp->left = a,tmp->right = b;
|
||||||
|
hp.push(*tmp);
|
||||||
|
}
|
||||||
|
root = hp.top();
|
||||||
|
preOrder(&root,string());
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
void huffman<ky,wt>::preOrder(node<ky, wt>* nd,string s)
|
||||||
|
{
|
||||||
|
if(nd->left == NULL){
|
||||||
|
encode_map[nd->key] =s;
|
||||||
|
decode_map[s] = nd->key;
|
||||||
|
delete nd;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
preOrder(nd->left,s+'0');
|
||||||
|
preOrder(nd->right,s+'1');
|
||||||
|
delete nd;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
string huffman<ky,wt>::decode(string zipfile_name,long &charNum)
|
||||||
|
{
|
||||||
|
string uniFileName(string);
|
||||||
|
FILE * src = fopen(zipfile_name.c_str(),"rb");
|
||||||
|
char file_name[nameLength];
|
||||||
|
fgets(file_name,nameLength,src);
|
||||||
|
int ct=-1;
|
||||||
|
while(file_name[++ct]!='\n');
|
||||||
|
int pos = zipfile_name.find('.');
|
||||||
|
if(pos==string::npos)pos=zipfile_name.size();
|
||||||
|
string name(zipfile_name.substr(0,pos)) ,suffix(file_name,file_name+ct),file(name+suffix);
|
||||||
|
file=uniFileName(file);
|
||||||
|
cout<<"extracting compressed file :"<<zipfile_name<<endl;
|
||||||
|
FILE * f = fopen(file.c_str(),"wb");
|
||||||
|
char t[numDigit];
|
||||||
|
fgets(t,numDigit,src);
|
||||||
|
int sz=atoi(t);
|
||||||
|
char code[sz];
|
||||||
|
fread(code,sz,1,src);
|
||||||
|
int idx=0;
|
||||||
|
for(int i =0;i<sz;++i ){
|
||||||
|
if(code[i]==' '){
|
||||||
|
decode_map[string(code+idx,code+i)]=code[++i];
|
||||||
|
idx=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=0;i<starNum;++i)cout<<"@";
|
||||||
|
cout<<endl;
|
||||||
|
char c;
|
||||||
|
long cur=charNum,gap=charNum/starNum;
|
||||||
|
while(cur){
|
||||||
|
c=fgetc(src);
|
||||||
|
if(!((--cur)%gap))cout<<"@"<<flush;
|
||||||
|
for(int i =0;i<8;++i){
|
||||||
|
if(c&(1<<i))res.append(1,'1');
|
||||||
|
else res.append(1,'0');
|
||||||
|
if(decode_map.count(res)!=0){
|
||||||
|
fputc(decode_map[res],f);
|
||||||
|
res.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
c=fgetc(src);
|
||||||
|
int dgt=fgetc(src);
|
||||||
|
cout<<feof(f);
|
||||||
|
if((int)dgt!=-1 ){
|
||||||
|
for(int i =0;i<dgt;++i){
|
||||||
|
if(c&(1<<i))res.append(1,'1');
|
||||||
|
else res.append(1,'0');
|
||||||
|
if(decode_map.count(res)!=0){
|
||||||
|
fputc(decode_map[res],f);
|
||||||
|
res.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(src);
|
||||||
|
fclose(f);
|
||||||
|
cout<<"get "<<file <<" successfully"<<endl;
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
string huffman<ky,wt>::encode(string file_name,long &charNum)
|
||||||
|
{
|
||||||
|
charNum=0;
|
||||||
|
string uniFileName(string);
|
||||||
|
int pos =file_name.rfind('.');
|
||||||
|
if(pos==string::npos)pos=file_name.size();
|
||||||
|
string zipfile = file_name.substr(0,pos)+string(".zzip");
|
||||||
|
zipfile = uniFileName(zipfile);
|
||||||
|
cout<<"generating zip file :"<<zipfile<<endl;
|
||||||
|
FILE * dst = fopen(zipfile.c_str(),"wb");
|
||||||
|
FILE * f = fopen(file_name.c_str(),"rb");
|
||||||
|
fputs(file_name.substr(pos).c_str(),dst);
|
||||||
|
fputc('\n',dst);
|
||||||
|
string data;
|
||||||
|
for(class map<string,ky>::iterator i=decode_map.begin();i!=decode_map.end() ;++i ){
|
||||||
|
data.append((i->first));
|
||||||
|
data.append(" ");
|
||||||
|
data+=(i->second);
|
||||||
|
}
|
||||||
|
int data_size = data.size(); // calculate the size of the code_data
|
||||||
|
char sz[numDigit];
|
||||||
|
itoa(data_size,sz,numDigit);
|
||||||
|
int ct=0;
|
||||||
|
for(;sz[ct];++ct)fputc(sz[ct],dst);
|
||||||
|
fputc('\n',dst);
|
||||||
|
fwrite(data.c_str(),data_size,1,dst);
|
||||||
|
int sum=0,digit=0,num;
|
||||||
|
string code8;
|
||||||
|
for(int i=0;i<starNum;++i)cout<<"@";
|
||||||
|
cout<<endl;
|
||||||
|
long gap=root.val/starNum,cur=0;
|
||||||
|
while(!feof(f)){
|
||||||
|
code8=encode_map[fgetc(f)];
|
||||||
|
if(!((++cur)%gap))cout<<"@";
|
||||||
|
for(int i=0;i<code8.size();++i){
|
||||||
|
if(code8[i]=='1')sum += 1<<(digit); //mistake if(tmp[j])
|
||||||
|
++digit;
|
||||||
|
if(digit==8){
|
||||||
|
++charNum;
|
||||||
|
fputc(sum,dst);
|
||||||
|
digit=sum=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
if(digit!=0){ //mark
|
||||||
|
fputc(sum,dst);
|
||||||
|
fputc(digit,dst);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
fclose(dst);
|
||||||
|
cout<<"compress "<<file_name <<" successfully"<<endl;
|
||||||
|
return zipfile;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
void huffman<ky,wt>::display()
|
||||||
|
{
|
||||||
|
cout<<"the encoding map,huffman codes are as bellow:"<<endl;
|
||||||
|
for (typename map<ky,string>::iterator i=encode_map.begin();i!=encode_map.end() ;++i )
|
||||||
|
cout<<i->first<<"("<<(int)i->first<<"):"<<i->second<<endl;
|
||||||
|
}
|
||||||
|
bool handle_one(string file_name,vector<long> &origin,vector<long> &compressed)
|
||||||
|
{
|
||||||
|
int name_length = file_name.size();
|
||||||
|
FILE *src=fopen(file_name.c_str(),"rb");
|
||||||
|
cout<<"opening "<<file_name<<"..."<<endl;
|
||||||
|
if(!src){
|
||||||
|
cout<<"Path Error! Opening "<<file_name<<" Failed"<<endl;
|
||||||
|
origin.push_back(0);
|
||||||
|
compressed.push_back(0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
char cur;
|
||||||
|
map<char,long> mp;
|
||||||
|
while(!feof(src)){
|
||||||
|
fread(&cur,sizeof(char),1,src);
|
||||||
|
if(mp.count(cur)){
|
||||||
|
mp[cur]+=1;
|
||||||
|
}
|
||||||
|
else mp[cur]=1;
|
||||||
|
}
|
||||||
|
fclose(src);
|
||||||
|
huffman<char,long> hf(mp);
|
||||||
|
long sz;
|
||||||
|
string s(hf.encode(file_name,sz));
|
||||||
|
origin.push_back(hf.total()),compressed.push_back(sz);
|
||||||
|
cout<<"\ncontinue to uncompress? [Y/n]"<<endl;
|
||||||
|
char c=cin.get();
|
||||||
|
if(c=='n')return true;
|
||||||
|
hf.decode(s,sz);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool isSep(char c)
|
||||||
|
{
|
||||||
|
return c==' '||c=='\n'||c=='\t'||c==',';
|
||||||
|
}
|
||||||
|
void splitToVec(char * s,vector<string>& v)
|
||||||
|
{
|
||||||
|
int i=0,last=0;
|
||||||
|
for(;s[i];++i){
|
||||||
|
if(isSep(s[i])){
|
||||||
|
v.push_back(string(s+last,s+i));
|
||||||
|
while(s[++i]&&isSep(s[i]));
|
||||||
|
last=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(s[last])v.push_back(string(s+last,s+i));
|
||||||
|
}
|
||||||
|
bool lenStr(string &a,string &b)
|
||||||
|
{
|
||||||
|
return a.size()<b.size();
|
||||||
|
}
|
||||||
|
void go(vector<string> & names)
|
||||||
|
{
|
||||||
|
vector<long> originSize,compressedSize;
|
||||||
|
vector<int> deltaTime;
|
||||||
|
double last;
|
||||||
|
vector<bool> indicator;
|
||||||
|
bool bl;
|
||||||
|
for(vector<string>::iterator i=names.begin();i!=names.end();++i){
|
||||||
|
last=GetTickCount();
|
||||||
|
bl=handle_one(*i,originSize,compressedSize);
|
||||||
|
indicator.push_back(bl);
|
||||||
|
deltaTime.push_back(GetTickCount()-last);
|
||||||
|
}
|
||||||
|
cout<<"\ndealt file number "<<originSize.size()<<fixed<<setprecision(2)<<endl;
|
||||||
|
vector<string>::iterator p=max_element(names.begin(),names.end(),lenStr);
|
||||||
|
int len = p->size()+2;
|
||||||
|
for(int i =0;i<names.size();++i){
|
||||||
|
if(! indicator[i]){continue;}
|
||||||
|
cout<<names[i]<<string(len-names[i].size(),' ');
|
||||||
|
cout<<deltaTime[i]<<"ms "<<compressedSize[i]/1024.0<<"KB/"<<originSize[i]/1024.0<<"KB :";
|
||||||
|
cout<<compressedSize[i]*100.0/originSize[i]<<"%"<<endl;
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
system("pause");
|
||||||
|
system("pause");
|
||||||
|
}
|
||||||
|
int main(int argv,char ** argc)
|
||||||
|
{
|
||||||
|
_chdir("C:\\Users\\mbinary\\Desktop\\dataStructrue\\huffman");
|
||||||
|
char cwd[50];
|
||||||
|
cout<<getcwd(cwd,50)<<endl;
|
||||||
|
string file1("GitHubDesktopSetup.exe");
|
||||||
|
string file("³õÐÄδ¸Ä.mp4");
|
||||||
|
vector<string> names;
|
||||||
|
if(argv>1){
|
||||||
|
for(int i=1;i<argv;++i){
|
||||||
|
names.push_back(argc[i]);
|
||||||
|
}
|
||||||
|
go(names);
|
||||||
|
names.clear();
|
||||||
|
}
|
||||||
|
char mk;
|
||||||
|
while(1){
|
||||||
|
char s[201];
|
||||||
|
cout<<"input file names separated by space "<<endl;
|
||||||
|
cout<<"OR press enter to use the default file:"<<file<<endl;
|
||||||
|
if(cin.peek()=='\n')names.push_back(file);
|
||||||
|
else {
|
||||||
|
cin.getline(s,200);
|
||||||
|
splitToVec(s,names);
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
go(names);
|
||||||
|
cout<<"continue to compress or uncompress files? [Y/n]:"<<flush;
|
||||||
|
mk= cin.get();
|
||||||
|
if(mk=='n')break;
|
||||||
|
names.clear();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
38
codes/dataStructure/huffman/huffman.aux
Normal file
38
codes/dataStructure/huffman/huffman.aux
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
\relax
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {1}需求分析}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{1}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{2}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{3}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{4}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{5}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {2}概要设计}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}结点node}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{数据对象}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{数据关系}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{基本操作}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{node()}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{node( const node\& nd}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{operator<}{2}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {2.2}huffman树}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{数据对象}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{数据关系}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {paragraph}{基本操作}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{huffman( map)}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{encode(string)}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{decode(string)}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{preorder()}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subparagraph}{display}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {3}详细设计}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}编码,解码算法}{3}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}输出进度条}{7}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3}改变文件名}{7}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {3.4}统计信息}{7}}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {4}调试分析}{8}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {4.1}编码信息的存储}{8}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {4.2}最后一个字节}{8}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {4.3}文件名的处理}{8}}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {5}用户手册}{8}}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {6}测试结果}{9}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {6.1}文本文件}{9}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {6.2}二进制文件1}{10}}
|
||||||
|
\@writefile{toc}{\contentsline {subsection}{\numberline {6.3}二进制文件2}{11}}
|
363
codes/dataStructure/huffman/huffman.cc
Normal file
363
codes/dataStructure/huffman/huffman.cc
Normal file
|
@ -0,0 +1,363 @@
|
||||||
|
#include<math.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<direct.h>
|
||||||
|
#include<iostream>
|
||||||
|
#include<algorithm>
|
||||||
|
#include<map>
|
||||||
|
#include<windows.h>
|
||||||
|
#include<iomanip>
|
||||||
|
#include<string>
|
||||||
|
#include<vector>
|
||||||
|
#include<queue>
|
||||||
|
#define numDigit 10
|
||||||
|
#define nameLength 50
|
||||||
|
#define starNum 80
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void cat(string s)
|
||||||
|
{
|
||||||
|
FILE* f=fopen(s.c_str(),"rb");
|
||||||
|
cout<<"file content"<<endl;
|
||||||
|
while(!feof(f)){
|
||||||
|
cout<<fgetc(f);
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
}
|
||||||
|
string uniFileName(string file)
|
||||||
|
{
|
||||||
|
FILE * check = fopen(file.c_str(),"rb");
|
||||||
|
if(check){
|
||||||
|
char c;
|
||||||
|
cout<<"the file "<<file<<" already exists! continue? [Y/n]:"<<flush;
|
||||||
|
c=cin.get();
|
||||||
|
if(c=='n')exit(0);
|
||||||
|
int p,q;
|
||||||
|
p= file.find('(');
|
||||||
|
q=file.rfind('.');
|
||||||
|
if(q==string::npos)q=file.size();
|
||||||
|
if(p==string::npos)p=q;
|
||||||
|
string name=file.substr(0,p),suffix=file.substr(q,file.size());
|
||||||
|
int n=0;
|
||||||
|
while(true){
|
||||||
|
char s[3];
|
||||||
|
n+=1;
|
||||||
|
itoa(n,s,10);
|
||||||
|
file=(name+"("+s+")"+suffix);
|
||||||
|
FILE* f=fopen(file.c_str(),"rb");
|
||||||
|
if(!f)break;
|
||||||
|
else fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
template<class t1, class t2>
|
||||||
|
void mapprint(map<t1,t2> &f)
|
||||||
|
{
|
||||||
|
for(class map<t1,t2>::iterator i = f.begin();i!=f.end();++i)
|
||||||
|
cout<<i->first<<") : "<<i->second<<endl;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
class node
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ky key;
|
||||||
|
wt val;
|
||||||
|
bool visited;
|
||||||
|
node * left,*right;
|
||||||
|
node(const node &a){val = a.val;key= a.key;visited = a.visited;left= a.left;right=a.right;}
|
||||||
|
node(ky k=0,wt v=0):key(k),val(v),visited(false),left(NULL),right(NULL){};
|
||||||
|
bool operator<(const node<ky,wt> & a)const{return val>a.val;};
|
||||||
|
};
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
class huffman
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
node<ky,wt> root;
|
||||||
|
string res;
|
||||||
|
public:
|
||||||
|
long total(){return root.val;}
|
||||||
|
map<ky,string> encode_map;
|
||||||
|
map<string,ky> decode_map;
|
||||||
|
huffman(map<ky,wt>& mp);
|
||||||
|
void display();
|
||||||
|
string encode(string,long &);
|
||||||
|
string decode(string,long&);
|
||||||
|
void preOrder(node<ky,wt>*,string);
|
||||||
|
};
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
huffman<ky,wt>::huffman(map<ky,wt>& mp)
|
||||||
|
{
|
||||||
|
if(mp.empty()){
|
||||||
|
cout<<"Error! No data!"<<endl;
|
||||||
|
root=NULL;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
priority_queue<node<ky,wt> > hp;
|
||||||
|
for(typename map<ky,wt>::iterator i=mp.begin();i!=mp.end();++i){
|
||||||
|
hp.push( node<ky,wt>(i->first,i->second));
|
||||||
|
}
|
||||||
|
int n =hp.size();
|
||||||
|
if(n==1){
|
||||||
|
root = hp.top();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while(--n>=1){
|
||||||
|
node<ky,wt> *a = new node<ky,wt>(hp.top());
|
||||||
|
hp.pop();
|
||||||
|
node<ky,wt> *b = new node<ky,wt>(hp.top());
|
||||||
|
hp.pop();
|
||||||
|
node<ky,wt> * tmp = new node<ky,wt>(0,a->val+b->val);
|
||||||
|
tmp->left = a,tmp->right = b;
|
||||||
|
hp.push(*tmp);
|
||||||
|
}
|
||||||
|
root = hp.top();
|
||||||
|
preOrder(&root,string());
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
void huffman<ky,wt>::preOrder(node<ky, wt>* nd,string s)
|
||||||
|
{
|
||||||
|
if(nd->left == NULL){
|
||||||
|
encode_map[nd->key] =s;
|
||||||
|
decode_map[s] = nd->key;
|
||||||
|
delete nd;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
preOrder(nd->left,s+'0');
|
||||||
|
preOrder(nd->right,s+'1');
|
||||||
|
delete nd;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
string huffman<ky,wt>::decode(string zipfile_name,long &charNum)
|
||||||
|
{
|
||||||
|
string uniFileName(string);
|
||||||
|
FILE * src = fopen(zipfile_name.c_str(),"rb");
|
||||||
|
char file_name[nameLength];
|
||||||
|
fgets(file_name,nameLength,src);
|
||||||
|
int ct=-1;
|
||||||
|
while(file_name[++ct]!='\n');
|
||||||
|
int pos = zipfile_name.find('.');
|
||||||
|
if(pos==string::npos)pos=zipfile_name.size();
|
||||||
|
string name(zipfile_name.substr(0,pos)) ,suffix(file_name,file_name+ct),file(name+suffix);
|
||||||
|
file=uniFileName(file);
|
||||||
|
cout<<"extracting compressed file :"<<zipfile_name<<endl;
|
||||||
|
FILE * f = fopen(file.c_str(),"wb");
|
||||||
|
char t[numDigit];
|
||||||
|
fgets(t,numDigit,src);
|
||||||
|
int sz=atoi(t);
|
||||||
|
char code[sz];
|
||||||
|
fread(code,sz,1,src);
|
||||||
|
int idx=0;
|
||||||
|
for(int i =0;i<sz;++i ){
|
||||||
|
if(code[i]==' '){
|
||||||
|
decode_map[string(code+idx,code+i)]=code[++i];
|
||||||
|
idx=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=0;i<starNum;++i)cout<<"@";
|
||||||
|
cout<<endl;
|
||||||
|
char c;
|
||||||
|
long cur=charNum,gap=charNum/starNum;
|
||||||
|
while(cur){
|
||||||
|
c=fgetc(src);
|
||||||
|
if(!((--cur)%gap))cout<<"@"<<flush;
|
||||||
|
for(int i =0;i<8;++i){
|
||||||
|
if(c&(1<<i))res.append(1,'1');
|
||||||
|
else res.append(1,'0');
|
||||||
|
if(decode_map.count(res)!=0){
|
||||||
|
fputc(decode_map[res],f);
|
||||||
|
res.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
c=fgetc(src);
|
||||||
|
int dgt=fgetc(src);
|
||||||
|
cout<<feof(f);
|
||||||
|
if((int)dgt!=-1 ){
|
||||||
|
for(int i =0;i<dgt;++i){
|
||||||
|
if(c&(1<<i))res.append(1,'1');
|
||||||
|
else res.append(1,'0');
|
||||||
|
if(decode_map.count(res)!=0){
|
||||||
|
fputc(decode_map[res],f);
|
||||||
|
res.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(src);
|
||||||
|
fclose(f);
|
||||||
|
cout<<"get "<<file <<" successfully"<<endl;
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
string huffman<ky,wt>::encode(string file_name,long &charNum)
|
||||||
|
{
|
||||||
|
charNum=0;
|
||||||
|
string uniFileName(string);
|
||||||
|
int pos =file_name.rfind('.');
|
||||||
|
if(pos==string::npos)pos=file_name.size();
|
||||||
|
string zipfile = file_name.substr(0,pos)+string(".zzip");
|
||||||
|
zipfile = uniFileName(zipfile);
|
||||||
|
cout<<"generating zip file :"<<zipfile<<endl;
|
||||||
|
FILE * dst = fopen(zipfile.c_str(),"wb");
|
||||||
|
FILE * f = fopen(file_name.c_str(),"rb");
|
||||||
|
fputs(file_name.substr(pos).c_str(),dst);
|
||||||
|
fputc('\n',dst);
|
||||||
|
string data;
|
||||||
|
for(class map<string,ky>::iterator i=decode_map.begin();i!=decode_map.end() ;++i ){
|
||||||
|
data.append((i->first));
|
||||||
|
data.append(" ");
|
||||||
|
data+=(i->second);
|
||||||
|
}
|
||||||
|
int data_size = data.size(); // calculate the size of the code_data
|
||||||
|
char sz[numDigit];
|
||||||
|
itoa(data_size,sz,numDigit);
|
||||||
|
int ct=0;
|
||||||
|
for(;sz[ct];++ct)fputc(sz[ct],dst);
|
||||||
|
fputc('\n',dst);
|
||||||
|
fwrite(data.c_str(),data_size,1,dst);
|
||||||
|
int sum=0,digit=0,num;
|
||||||
|
string code8;
|
||||||
|
for(int i=0;i<starNum;++i)cout<<"@";
|
||||||
|
cout<<endl;
|
||||||
|
long gap=root.val/starNum,cur=0;
|
||||||
|
while(!feof(f)){
|
||||||
|
code8=encode_map[fgetc(f)];
|
||||||
|
if(!((++cur)%gap))cout<<"@";
|
||||||
|
for(int i=0;i<code8.size();++i){
|
||||||
|
if(code8[i]=='1')sum += 1<<(digit); //mistake if(tmp[j])
|
||||||
|
++digit;
|
||||||
|
if(digit==8){
|
||||||
|
++charNum;
|
||||||
|
fputc(sum,dst);
|
||||||
|
digit=sum=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
if(digit!=0){ //mark
|
||||||
|
fputc(sum,dst);
|
||||||
|
fputc(digit,dst);
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
fclose(dst);
|
||||||
|
cout<<"compress "<<file_name <<" successfully"<<endl;
|
||||||
|
return zipfile;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
void huffman<ky,wt>::display()
|
||||||
|
{
|
||||||
|
cout<<"the encoding map,huffman codes are as bellow:"<<endl;
|
||||||
|
for (typename map<ky,string>::iterator i=encode_map.begin();i!=encode_map.end() ;++i )
|
||||||
|
cout<<i->first<<"("<<(int)i->first<<"):"<<i->second<<endl;
|
||||||
|
}
|
||||||
|
bool handle_one(string file_name,vector<long> &origin,vector<long> &compressed)
|
||||||
|
{
|
||||||
|
int name_length = file_name.size();
|
||||||
|
FILE *src=fopen(file_name.c_str(),"rb");
|
||||||
|
cout<<"opening "<<file_name<<"..."<<endl;
|
||||||
|
if(!src){
|
||||||
|
cout<<"Path Error! Opening "<<file_name<<" Failed"<<endl;
|
||||||
|
origin.push_back(0);
|
||||||
|
compressed.push_back(0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
char cur;
|
||||||
|
map<char,long> mp;
|
||||||
|
while(!feof(src)){
|
||||||
|
fread(&cur,sizeof(char),1,src);
|
||||||
|
if(mp.count(cur)){
|
||||||
|
mp[cur]+=1;
|
||||||
|
}
|
||||||
|
else mp[cur]=1;
|
||||||
|
}
|
||||||
|
fclose(src);
|
||||||
|
huffman<char,long> hf(mp);
|
||||||
|
long sz;
|
||||||
|
string s(hf.encode(file_name,sz));
|
||||||
|
origin.push_back(hf.total()),compressed.push_back(sz);
|
||||||
|
cout<<"\ncontinue to uncompress? [Y/n]"<<endl;
|
||||||
|
char c=cin.get();
|
||||||
|
if(c=='n')return true;
|
||||||
|
hf.decode(s,sz);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool isSep(char c)
|
||||||
|
{
|
||||||
|
return c==' '||c=='\n'||c=='\t'||c==',';
|
||||||
|
}
|
||||||
|
void splitToVec(char * s,vector<string>& v)
|
||||||
|
{
|
||||||
|
int i=0,last=0;
|
||||||
|
for(;s[i];++i){
|
||||||
|
if(isSep(s[i])){
|
||||||
|
v.push_back(string(s+last,s+i));
|
||||||
|
while(s[++i]&&isSep(s[i]));
|
||||||
|
last=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(s[last])v.push_back(string(s+last,s+i));
|
||||||
|
}
|
||||||
|
bool lenStr(string &a,string &b)
|
||||||
|
{
|
||||||
|
return a.size()<b.size();
|
||||||
|
}
|
||||||
|
void go(vector<string> & names)
|
||||||
|
{
|
||||||
|
vector<long> originSize,compressedSize;
|
||||||
|
vector<int> deltaTime;
|
||||||
|
double last;
|
||||||
|
vector<bool> indicator;
|
||||||
|
bool bl;
|
||||||
|
for(vector<string>::iterator i=names.begin();i!=names.end();++i){
|
||||||
|
last=GetTickCount();
|
||||||
|
bl=handle_one(*i,originSize,compressedSize);
|
||||||
|
indicator.push_back(bl);
|
||||||
|
deltaTime.push_back(GetTickCount()-last);
|
||||||
|
}
|
||||||
|
cout<<"\ndealt file number "<<originSize.size()<<fixed<<setprecision(2)<<endl;
|
||||||
|
vector<string>::iterator p=max_element(names.begin(),names.end(),lenStr);
|
||||||
|
int len = p->size()+2;
|
||||||
|
for(int i =0;i<names.size();++i){
|
||||||
|
if(! indicator[i]){continue;}
|
||||||
|
cout<<names[i]<<string(len-names[i].size(),' ');
|
||||||
|
cout<<deltaTime[i]<<"ms "<<compressedSize[i]/1024.0<<"KB/"<<originSize[i]/1024.0<<"KB :";
|
||||||
|
cout<<compressedSize[i]*100.0/originSize[i]<<"%"<<endl;
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
system("pause");
|
||||||
|
system("pause");
|
||||||
|
}
|
||||||
|
int main(int argv,char ** argc)
|
||||||
|
{
|
||||||
|
char cwd[50];
|
||||||
|
cout<<getcwd(cwd,50)<<endl;
|
||||||
|
string file1("GitHubDesktopSetup.exe");
|
||||||
|
string file("³õÐÄδ¸Ä.mp4");
|
||||||
|
vector<string> names;
|
||||||
|
if(argv>1){
|
||||||
|
for(int i=1;i<argv;++i){
|
||||||
|
names.push_back(argc[i]);
|
||||||
|
}
|
||||||
|
go(names);
|
||||||
|
names.clear();
|
||||||
|
}
|
||||||
|
char mk;
|
||||||
|
while(1){
|
||||||
|
char s[201];
|
||||||
|
cout<<"input file names separated by space "<<endl;
|
||||||
|
cout<<"OR press enter to use the default file:"<<file<<endl;
|
||||||
|
if(cin.peek()=='\n')names.push_back(file);
|
||||||
|
else {
|
||||||
|
cin.getline(s,200);
|
||||||
|
splitToVec(s,names);
|
||||||
|
}
|
||||||
|
cout<<endl;
|
||||||
|
go(names);
|
||||||
|
cout<<"continue to compress or uncompress files? [Y/n]:"<<flush;
|
||||||
|
mk= cin.get();
|
||||||
|
if(mk=='n')break;
|
||||||
|
names.clear();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
codes/dataStructure/huffman/huffman.exe
Normal file
BIN
codes/dataStructure/huffman/huffman.exe
Normal file
Binary file not shown.
1537
codes/dataStructure/huffman/huffman.log
Normal file
1537
codes/dataStructure/huffman/huffman.log
Normal file
File diff suppressed because it is too large
Load Diff
BIN
codes/dataStructure/huffman/huffman.o
Normal file
BIN
codes/dataStructure/huffman/huffman.o
Normal file
Binary file not shown.
BIN
codes/dataStructure/huffman/huffman.pdf
Normal file
BIN
codes/dataStructure/huffman/huffman.pdf
Normal file
Binary file not shown.
BIN
codes/dataStructure/huffman/huffman.synctex.gz
Normal file
BIN
codes/dataStructure/huffman/huffman.synctex.gz
Normal file
Binary file not shown.
310
codes/dataStructure/huffman/huffman.tex
Normal file
310
codes/dataStructure/huffman/huffman.tex
Normal file
|
@ -0,0 +1,310 @@
|
||||||
|
%\document{article}
|
||||||
|
\documentclass[UTF8]{ctexart}
|
||||||
|
\usepackage{amsmath}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
\usepackage{fancyhdr}
|
||||||
|
\usepackage{float}
|
||||||
|
\usepackage{listings}
|
||||||
|
\title{Huffman编码压缩}
|
||||||
|
\author{朱河勤 PB16030899}
|
||||||
|
\pagestyle{fancy}
|
||||||
|
\lfoot{朱河勤 PB16030899}
|
||||||
|
\chead{Huffman编码压缩}
|
||||||
|
\rfoot{2017/11/11}
|
||||||
|
\begin{document}
|
||||||
|
\maketitle
|
||||||
|
|
||||||
|
\tableofcontents
|
||||||
|
\section{需求分析}
|
||||||
|
|
||||||
|
|
||||||
|
\paragraph{1}
|
||||||
|
正确创建huffman 树,并得到huffman编码
|
||||||
|
\paragraph{2}
|
||||||
|
压缩编码文件,使一般的文本文件变小,二进制文件可能不会变小
|
||||||
|
\paragraph{3}
|
||||||
|
解压文件,注意生成的文件要考虑同名,所以要考虑文件名的操作
|
||||||
|
\paragraph{4}
|
||||||
|
压缩解压时显示进度条
|
||||||
|
\paragraph{5}
|
||||||
|
解压完毕,统计文件数,压缩率,压缩时间等等
|
||||||
|
|
||||||
|
|
||||||
|
\section{概要设计}
|
||||||
|
\subsection{结点node}
|
||||||
|
ADT linkList\{\\
|
||||||
|
\paragraph{数据对象}:key , val, visited ,left,right \\
|
||||||
|
\paragraph{数据关系}:属性集合\\
|
||||||
|
\paragraph{基本操作}:
|
||||||
|
\subparagraph{node()} 新建一个结点
|
||||||
|
\subparagraph{node( const node\& nd} 复制一个结点
|
||||||
|
\subparagraph{operator<}重载操作符<
|
||||||
|
\}
|
||||||
|
\subsection{huffman树}
|
||||||
|
ADT linkList\{\\
|
||||||
|
\paragraph{数据对象}:root , encode\_map, total\\
|
||||||
|
\paragraph{数据关系}:属性集合\\
|
||||||
|
\paragraph{基本操作}:
|
||||||
|
\subparagraph{huffman( map)}传递字符的频率信息以map形式, 然后建立huffman树
|
||||||
|
\subparagraph{encode(string)} 传递文件名,压缩
|
||||||
|
\subparagraph{decode(string)} 传递文件名,解压缩
|
||||||
|
\subparagraph{preorder()}先序遍历,获得huffman编码
|
||||||
|
\subparagraph{display}显示所有信息,包括结点信息,以及huffman编码
|
||||||
|
\}
|
||||||
|
|
||||||
|
|
||||||
|
\section{详细设计}
|
||||||
|
\subsection{编码,解码算法}
|
||||||
|
\begin{lstlisting}[language=c++]
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
void huffman<ky,wt>::preOrder(node<ky, wt>* nd,string s)
|
||||||
|
{
|
||||||
|
if(nd->left == NULL){
|
||||||
|
encode_map[nd->key] =s;
|
||||||
|
decode_map[s] = nd->key;
|
||||||
|
delete nd;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
preOrder(nd->left,s+'0');
|
||||||
|
preOrder(nd->right,s+'1');
|
||||||
|
delete nd;
|
||||||
|
}
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
string huffman<ky,wt>::decode(string zipfile_name)
|
||||||
|
{
|
||||||
|
string uniFileName(string);
|
||||||
|
FILE * src = fopen(zipfile_name.c_str(),"rb");
|
||||||
|
char file_name[nameLength];
|
||||||
|
fgets(file_name,nameLength,src);
|
||||||
|
int ct=-1;
|
||||||
|
while(file_name[++ct]!='\n');
|
||||||
|
int pos = zipfile_name.find('.');
|
||||||
|
if(pos==string::npos)pos=zipfile_name.size();
|
||||||
|
string name(zipfile_name.substr(0,pos)) ,suffix(file_name,file_name+ct),file(name+suffix);
|
||||||
|
file=uniFileName(file);
|
||||||
|
cout<<"extracting compressed file :"<<file<<endl;
|
||||||
|
FILE * f = fopen(file.c_str(),"wb");
|
||||||
|
if(!f){
|
||||||
|
cerr<<"Error! Maybe the file doesn't exist!"<<endl;cerr<<"open error!"<<endl;
|
||||||
|
abort( );
|
||||||
|
}
|
||||||
|
char t[numDigit];
|
||||||
|
fgets(t,numDigit,src);
|
||||||
|
int sz=atoi(t);
|
||||||
|
char code[sz];
|
||||||
|
fread(code,sz,1,src);
|
||||||
|
cout<<code<<endl;
|
||||||
|
cout<<"SZ"<<sz<<endl;
|
||||||
|
// return string();
|
||||||
|
map<string,char> mp;
|
||||||
|
int idx=0;
|
||||||
|
for(int i =0;i<sz;++i ){
|
||||||
|
if(code[i]==' '){
|
||||||
|
mp[string(code+idx,code+i)]=code[++i];
|
||||||
|
idx=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mapprint(mp);
|
||||||
|
char buff[once],*p;
|
||||||
|
string res;
|
||||||
|
while(!feof(src)){
|
||||||
|
p=buff;
|
||||||
|
int cur=0;
|
||||||
|
while(cur<once){
|
||||||
|
ToEightBin(p,fgetc(src));
|
||||||
|
}
|
||||||
|
cout<<buff;
|
||||||
|
return string();
|
||||||
|
while(buff[++cur]!='\0');
|
||||||
|
for(int i =0;i<cur;++i){
|
||||||
|
res.append(1,buff[i]);
|
||||||
|
if(mp.count(res)!=0){
|
||||||
|
fputc(mp[res],f);
|
||||||
|
res.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(src);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ky,typename wt>
|
||||||
|
string huffman<ky,wt>::encode(string file_name)
|
||||||
|
{
|
||||||
|
string uniFileName(string);
|
||||||
|
int pos =file_name.rfind('.');
|
||||||
|
if(pos==string::npos)pos=file_name.size();
|
||||||
|
string zipfile = file_name.substr(0,pos)+string(".zzip");
|
||||||
|
zipfile = uniFileName(zipfile);
|
||||||
|
cout<<"generating zip file :"<<zipfile<<endl;
|
||||||
|
FILE * dst = fopen(zipfile.c_str(),"wb");
|
||||||
|
FILE * f = fopen(file_name.c_str(),"rb");
|
||||||
|
fputs(file_name.substr(pos).c_str(),dst);
|
||||||
|
fputc('\n',dst);
|
||||||
|
string data;
|
||||||
|
for(class map<string,ky>::iterator i=decode_map.begin();i!=decode_map.end() ;++i ){
|
||||||
|
data.append((i->first));
|
||||||
|
data.append(" ");
|
||||||
|
data+=(i->second);
|
||||||
|
}
|
||||||
|
cout<<data<<endl<<"SZ"<<data.size()<<endl;;
|
||||||
|
// mapprint( encode_map);
|
||||||
|
// return string();
|
||||||
|
int data_size = data.size(); // calculate the size of the code_data
|
||||||
|
char sz[numDigit];
|
||||||
|
itoa(data_size,sz,numDigit);
|
||||||
|
int ct=0;
|
||||||
|
for(;sz[ct];++ct)fputc(sz[ct],dst);
|
||||||
|
fputc('\n',dst);
|
||||||
|
// cout<<data<<data_size<<endl;
|
||||||
|
fwrite(data.c_str(),data_size,1,dst);
|
||||||
|
int sum=0,digit=0,num;
|
||||||
|
char src[once];
|
||||||
|
while(!feof(f)){
|
||||||
|
num = fread(src,sizeof(char),once,f);
|
||||||
|
string tmp;
|
||||||
|
for(int i =0;i<num;++i){
|
||||||
|
tmp=encode_map[src[i]];
|
||||||
|
for(int j =0;j<tmp.size();++j){
|
||||||
|
if(tmp[j])sum += 1<<(digit%8);
|
||||||
|
++digit;
|
||||||
|
if(digit==8){
|
||||||
|
fputc(sum,dst);
|
||||||
|
digit=sum=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(digit!=0){ //mark
|
||||||
|
fputc(sum,dst);
|
||||||
|
fputc(digit,dst);
|
||||||
|
}
|
||||||
|
else fputc(0,dst);
|
||||||
|
fclose(f);
|
||||||
|
fclose(dst);
|
||||||
|
return zipfile;
|
||||||
|
}
|
||||||
|
\end{lstlisting}
|
||||||
|
\subsection{输出进度条}通过输出@以显示当天进度,提示用户
|
||||||
|
\subsection{改变文件名}由于当前工作目录可能有解压或压缩后的同名文件,要进行处理,我的方法是在后缀前,文件名后加上(n) 其中,n为数字
|
||||||
|
\subsection{统计信息}处理后,统计信息,包括压缩的文件名目录,所用的时间,文件大小,压缩率等等
|
||||||
|
|
||||||
|
\section{调试分析}
|
||||||
|
\subsection{编码信息的存储}
|
||||||
|
我先计算了编码信息的大小,然后存在文件中,以键值对的形式,如''001 k''再存储编码信息,这样就能更快的读取,并能节省空间
|
||||||
|
\subsection{最后一个字节}
|
||||||
|
由于储存时一char八位一次地储存,所以最后一字节可能凑不齐,我通过补0地方式,并在最后再增加一字节记录补0的个数来解决
|
||||||
|
\subsection{文件名的处理}
|
||||||
|
文件名要要记录后缀以识别文件种类,以及文件是否存在,能否打开,生成的文件是否重名。比如,当发现重名时,你要生成(n)形式,但可能(n)也已经存在,所以要一直检查(1),(2)...检查到一个较大的数,或者是,第一次未出现时,才能确定N
|
||||||
|
|
||||||
|
|
||||||
|
\section{用户手册}
|
||||||
|
本程序需要在windows环境下运行,可以直接打开.exe文件,或者在命令行,支持命令行参数\
|
||||||
|
下面为程序运行界面
|
||||||
|
\begin{verbatim}
|
||||||
|
C:\Users\mbinary\Desktop\dataStructrue\huffman
|
||||||
|
input file names separated by space
|
||||||
|
OR press enter to use the default file:初心未改.mp4
|
||||||
|
|
||||||
|
|
||||||
|
opening 初心未改.mp4...
|
||||||
|
the file 初心未改.zzip already exists! continue? [Y/n]:generating zip file :初心未改(2).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
compress 初心未改.mp4 successfully
|
||||||
|
|
||||||
|
continue to uncompress? [Y/n]
|
||||||
|
|
||||||
|
the file 初心未改(2).mp4 already exists! continue? [Y/n]:
|
||||||
|
extracting compressed file :初心未改(2).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
get 初心未改(3).mp4 successfully
|
||||||
|
|
||||||
|
dealt file number 1
|
||||||
|
初心未改.mp4 18891ms 8274.84KB/8296.13KB :99.74%
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
|
\section{测试结果}
|
||||||
|
\subsection{文本文件}
|
||||||
|
输入了几个不存在的文件,检查强壮性。同时发现文本文件压缩率还是很令人满意的
|
||||||
|
\begin{verbatim}
|
||||||
|
input file names separated by space
|
||||||
|
OR press enter to use the default file:初心未改.mp4
|
||||||
|
em cvem ven em.cc
|
||||||
|
|
||||||
|
opening em...
|
||||||
|
Path Error! Opening em Failed
|
||||||
|
opening cvem...
|
||||||
|
Path Error! Opening cvem Failed
|
||||||
|
opening ven...
|
||||||
|
Path Error! Opening ven Failed
|
||||||
|
opening em.cc...
|
||||||
|
the file em.zzip already exists! continue? [Y/n]:
|
||||||
|
generating zip file :em(2).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
compress em.cc successfully
|
||||||
|
|
||||||
|
continue to uncompress? [Y/n]
|
||||||
|
|
||||||
|
the file em(2).cc already exists! continue? [Y/n]:
|
||||||
|
extracting compressed file :em(2).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
get em(3).cc successfully
|
||||||
|
|
||||||
|
dealt file number 4
|
||||||
|
em.cc 2266ms 4.69KB/7.57KB :61.87%
|
||||||
|
\end{verbatim}
|
||||||
|
\subsection{二进制文件1}
|
||||||
|
几乎没有压缩,原因应该是.exe文件本来就压缩得很好了,几乎已经是随机的编码了,所以huffman没有效果,这也是文件不能重复压缩直至没有大小的原因。
|
||||||
|
\begin{verbatim}
|
||||||
|
input file names separated by space
|
||||||
|
OR press enter to use the default file:初心未改.mp4
|
||||||
|
GitHubDesktopSetup.exe
|
||||||
|
|
||||||
|
opening GitHubDesktopSetup.exe...
|
||||||
|
the file GitHubDesktopSetup.zzip already exists! continue? [Y/n]:
|
||||||
|
generating zip file :GitHubDesktopSetup(2).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
compress GitHubDesktopSetup.exe successfully
|
||||||
|
|
||||||
|
continue to uncompress? [Y/n]
|
||||||
|
|
||||||
|
the file GitHubDesktopSetup(2).exe already exists! continue? [Y/n]:
|
||||||
|
extracting compressed file :GitHubDesktopSetup(2).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
get GitHubDesktopSetup(3).exe successfully
|
||||||
|
|
||||||
|
dealt file number 1
|
||||||
|
GitHubDesktopSetup.exe 309610ms 81718.46KB/81718.46KB :100.00%
|
||||||
|
\end{verbatim}
|
||||||
|
\subsection{二进制文件2}
|
||||||
|
\begin{verbatim}
|
||||||
|
input file names separated by space
|
||||||
|
OR press enter to use the default file:初心未改.mp4
|
||||||
|
|
||||||
|
|
||||||
|
opening 初心未改.mp4...
|
||||||
|
the file 初心未改.zzip already exists! continue? [Y/n]:generating zip file :初心未改(3).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
compress 初心未改.mp4 successfully
|
||||||
|
|
||||||
|
continue to uncompress? [Y/n]
|
||||||
|
|
||||||
|
the file 初心未改(3).mp4 already exists! continue? [Y/n]:
|
||||||
|
extracting compressed file :初心未改(3).zzip
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
get 初心未改(4).mp4 successfully
|
||||||
|
|
||||||
|
dealt file number 1
|
||||||
|
初心未改.mp4 13688ms 8274.84KB/8296.13KB :99.74%
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
|
\clearpage
|
||||||
|
\end{document}
|
37
codes/dataStructure/huffman/huffman.toc
Normal file
37
codes/dataStructure/huffman/huffman.toc
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
\contentsline {section}{\numberline {1}需求分析}{2}
|
||||||
|
\contentsline {paragraph}{1}{2}
|
||||||
|
\contentsline {paragraph}{2}{2}
|
||||||
|
\contentsline {paragraph}{3}{2}
|
||||||
|
\contentsline {paragraph}{4}{2}
|
||||||
|
\contentsline {paragraph}{5}{2}
|
||||||
|
\contentsline {section}{\numberline {2}概要设计}{2}
|
||||||
|
\contentsline {subsection}{\numberline {2.1}结点node}{2}
|
||||||
|
\contentsline {paragraph}{数据对象}{2}
|
||||||
|
\contentsline {paragraph}{数据关系}{2}
|
||||||
|
\contentsline {paragraph}{基本操作}{2}
|
||||||
|
\contentsline {subparagraph}{node()}{2}
|
||||||
|
\contentsline {subparagraph}{node( const node\& nd}{2}
|
||||||
|
\contentsline {subparagraph}{operator<}{2}
|
||||||
|
\contentsline {subsection}{\numberline {2.2}huffman树}{3}
|
||||||
|
\contentsline {paragraph}{数据对象}{3}
|
||||||
|
\contentsline {paragraph}{数据关系}{3}
|
||||||
|
\contentsline {paragraph}{基本操作}{3}
|
||||||
|
\contentsline {subparagraph}{huffman( map)}{3}
|
||||||
|
\contentsline {subparagraph}{encode(string)}{3}
|
||||||
|
\contentsline {subparagraph}{decode(string)}{3}
|
||||||
|
\contentsline {subparagraph}{preorder()}{3}
|
||||||
|
\contentsline {subparagraph}{display}{3}
|
||||||
|
\contentsline {section}{\numberline {3}详细设计}{3}
|
||||||
|
\contentsline {subsection}{\numberline {3.1}编码,解码算法}{3}
|
||||||
|
\contentsline {subsection}{\numberline {3.2}输出进度条}{7}
|
||||||
|
\contentsline {subsection}{\numberline {3.3}改变文件名}{7}
|
||||||
|
\contentsline {subsection}{\numberline {3.4}统计信息}{7}
|
||||||
|
\contentsline {section}{\numberline {4}调试分析}{8}
|
||||||
|
\contentsline {subsection}{\numberline {4.1}编码信息的存储}{8}
|
||||||
|
\contentsline {subsection}{\numberline {4.2}最后一个字节}{8}
|
||||||
|
\contentsline {subsection}{\numberline {4.3}文件名的处理}{8}
|
||||||
|
\contentsline {section}{\numberline {5}用户手册}{8}
|
||||||
|
\contentsline {section}{\numberline {6}测试结果}{9}
|
||||||
|
\contentsline {subsection}{\numberline {6.1}文本文件}{9}
|
||||||
|
\contentsline {subsection}{\numberline {6.2}二进制文件1}{10}
|
||||||
|
\contentsline {subsection}{\numberline {6.3}二进制文件2}{11}
|
181
codes/dataStructure/leftHeap.py
Normal file
181
codes/dataStructure/leftHeap.py
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
from functools import total_ordering
|
||||||
|
@total_ordering
|
||||||
|
|
||||||
|
class node:
|
||||||
|
def __init__(self,val,freq=1,s=1,left=None,right=None):
|
||||||
|
self.val=val
|
||||||
|
self.freq=freq
|
||||||
|
self.s=s
|
||||||
|
if left is None or right is None:
|
||||||
|
self.left = left if left is not None else right
|
||||||
|
self.right =None
|
||||||
|
else:
|
||||||
|
if left.s<right.s:
|
||||||
|
left,right =right, left
|
||||||
|
self.left=left
|
||||||
|
self.right=right
|
||||||
|
self.s+=self.right.s
|
||||||
|
def __eq__(self,nd):
|
||||||
|
return self.val==nd.val
|
||||||
|
def __lt__(self,nd):
|
||||||
|
return self.val<nd.val
|
||||||
|
def __repr__(self):
|
||||||
|
return 'node(val=%d,freq=%d,s=%d)'%(self.val,self.freq,self.s)
|
||||||
|
|
||||||
|
class leftHeap:
|
||||||
|
def __init__(self,root=None):
|
||||||
|
self.root=root
|
||||||
|
def __bool__(self):
|
||||||
|
return self.root is not None
|
||||||
|
@staticmethod
|
||||||
|
def _merge(root,t): #-> int
|
||||||
|
if root is None:return t
|
||||||
|
if t is None:return root
|
||||||
|
if root<t:
|
||||||
|
root,t=t,root
|
||||||
|
root.right = leftHeap._merge(root.right,t)
|
||||||
|
if root.left is None or root.right is None:
|
||||||
|
root.s=1
|
||||||
|
if root.left is None:
|
||||||
|
root.left,root.right = root.right,None
|
||||||
|
else:
|
||||||
|
if root.left.s<root.right.s:
|
||||||
|
root.left,root.right = root.right,root.left
|
||||||
|
root.s = root.right.s+1
|
||||||
|
return root
|
||||||
|
def insert(self,nd):
|
||||||
|
if not isinstance(nd,node):nd = node(nd)
|
||||||
|
if self.root is None:
|
||||||
|
self.root=nd
|
||||||
|
return
|
||||||
|
if self.root==nd:
|
||||||
|
self.root.freq+=1
|
||||||
|
return
|
||||||
|
prt =self. _findPrt(self.root,nd,None)
|
||||||
|
if prt is None:
|
||||||
|
self.root=leftHeap._merge(self.root,nd)
|
||||||
|
else :
|
||||||
|
if prt.left==nd:
|
||||||
|
prt.left.freq+=1
|
||||||
|
else:prt.right.freq+=1
|
||||||
|
def remove(self,nd):
|
||||||
|
if not isinstance(nd,node):nd = node(nd)
|
||||||
|
if self.root==nd:
|
||||||
|
self.root=leftHeap._merge(self.root.left,self.root.right)
|
||||||
|
else:
|
||||||
|
prt = self._findPrt(self.root,nd,None)
|
||||||
|
if prt is not None:
|
||||||
|
if prt.left==nd:
|
||||||
|
prt.left=leftHeap._merge(prt.left.left,prt.left.right)
|
||||||
|
else:
|
||||||
|
prt.right=leftHeap._merge(prt.right.left,prt.right.right)
|
||||||
|
def find(self,nd):
|
||||||
|
if not isinstance(nd,node):nd = node(nd)
|
||||||
|
prt = self._findPrt(self.root,nd,self.root)
|
||||||
|
if prt is None or prt==nd:return prt
|
||||||
|
elif prt.left==nd:return prt.left
|
||||||
|
else:return prt.right
|
||||||
|
def _findPrt(self,root,nd,parent):
|
||||||
|
if not isinstance(nd,node):nd = node(nd)
|
||||||
|
if root is None or root<nd:return None
|
||||||
|
if root==nd:return parent
|
||||||
|
l=self._findPrt(root.left,nd,root)
|
||||||
|
return l if l is not None else self._findPrt(root.right,nd,root)
|
||||||
|
def getTop(self):
|
||||||
|
return self.root
|
||||||
|
def pop(self):
|
||||||
|
nd = self.root
|
||||||
|
self.remove(self.root.val)
|
||||||
|
return nd
|
||||||
|
def levelTraverse(self):
|
||||||
|
li = [(self.root,0)]
|
||||||
|
cur=0
|
||||||
|
while li:
|
||||||
|
nd,lv = li.pop(0)
|
||||||
|
if cur<lv:
|
||||||
|
cur=lv
|
||||||
|
print()
|
||||||
|
print(nd,end=' ')
|
||||||
|
else:print(nd,end=' ')
|
||||||
|
if nd.left is not None:li.append((nd.left,lv+1))
|
||||||
|
if nd.right is not None:li.append((nd.right,lv+1))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
lh = leftHeap()
|
||||||
|
data = [(i-3)**2 for i in range(20)]
|
||||||
|
for i in data:
|
||||||
|
lh . insert(i)
|
||||||
|
lh.levelTraverse()
|
||||||
|
print()
|
||||||
|
for i in data:
|
||||||
|
print(lh.getTop())
|
||||||
|
if lh.find(i) is not None:lh.remove(i)
|
||||||
|
'''
|
||||||
|
data = [(i-10)**2 for i in range(20)]
|
||||||
|
node(100,freq=1,s=3)
|
||||||
|
node(81,freq=2,s=3) node(64,freq=2,s=2)
|
||||||
|
node(16,freq=2,s=2) node(25,freq=2,s=2) node(49,freq=2,s=1) node(36,freq=2,s=1)
|
||||||
|
node(9,freq=2,s=1) node(4,freq=2,s=1) node(1,freq=2,s=1) node(0,freq=1,s=1)
|
||||||
|
node(100,freq=1,s=3)
|
||||||
|
node(81,freq=2,s=3)
|
||||||
|
node(64,freq=2,s=2)
|
||||||
|
node(49,freq=2,s=1)
|
||||||
|
node(36,freq=2,s=3)
|
||||||
|
node(25,freq=2,s=2)
|
||||||
|
node(16,freq=2,s=2)
|
||||||
|
node(9,freq=2,s=1)
|
||||||
|
node(4,freq=2,s=2)
|
||||||
|
node(1,freq=2,s=1)
|
||||||
|
node(0,freq=1,s=1)
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
None
|
||||||
|
'''
|
||||||
|
|
||||||
|
'''
|
||||||
|
data = [(i-3)**2 for i in range(20)]
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(225,freq=1,s=1)
|
||||||
|
node(196,freq=1,s=1)
|
||||||
|
node(169,freq=1,s=1)
|
||||||
|
node(144,freq=1,s=1)
|
||||||
|
node(121,freq=1,s=1)
|
||||||
|
node(100,freq=1,s=1)
|
||||||
|
node(81,freq=1,s=1)
|
||||||
|
node(64,freq=1,s=1)
|
||||||
|
node(49,freq=1,s=1)
|
||||||
|
node(36,freq=1,s=1)
|
||||||
|
node(25,freq=1,s=1)
|
||||||
|
node(16,freq=1,s=1)
|
||||||
|
node(9,freq=2,s=2)
|
||||||
|
node(4,freq=2,s=1) node(1,freq=2,s=1)
|
||||||
|
node(0,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
node(256,freq=1,s=1)
|
||||||
|
'''
|
103
codes/dataStructure/loserTree.py
Normal file
103
codes/dataStructure/loserTree.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
class loserTree:
|
||||||
|
'''if i<=lowExt p = (i+offset)//2
|
||||||
|
else p = (i+n-1-lowExt)//2
|
||||||
|
s is the num of the full subtree node
|
||||||
|
p is the index of tree
|
||||||
|
i is the index of players
|
||||||
|
offset is a num 2^k-1 just bigger than n
|
||||||
|
lowExt is the double node num of the lowest layer of the tree
|
||||||
|
'''
|
||||||
|
def __init__(self,players,reverse=False):
|
||||||
|
self.n=len(players)
|
||||||
|
self.tree = [0]*self.n
|
||||||
|
players.insert(0,0)
|
||||||
|
self.players=players
|
||||||
|
self.reverse=reverse
|
||||||
|
self.getNum()
|
||||||
|
self.tree[0] = self.initTree(1)
|
||||||
|
self.dir=None
|
||||||
|
def getNum(self):
|
||||||
|
i=1
|
||||||
|
while 2*i< self.n:i=i*2
|
||||||
|
if 2*i ==self. n:
|
||||||
|
self.lowExt=0
|
||||||
|
self.s = 2*i-1
|
||||||
|
else:
|
||||||
|
self.lowExt = (self.n-i)*2
|
||||||
|
self.s = i-1
|
||||||
|
self.offset = 2*i-1
|
||||||
|
def treeToArray(self,p):
|
||||||
|
return 2*p-self.offset if p>self.s else 2*p+self.lowExt-self.n+1
|
||||||
|
def arrayToTree(self,i):
|
||||||
|
return (i+self.offset)//2 if i<=self.lowExt else (i-self.lowExt+ self.n-1)//2
|
||||||
|
def win(self,a,b):
|
||||||
|
return a<b if self.reverse else a>b
|
||||||
|
def initTree(self,p):
|
||||||
|
if p>=self.n:
|
||||||
|
delta = p%2 #!!! good job notice delta mark the lchild or rchlid
|
||||||
|
return self.players[self.treeToArray(p//2)+delta]
|
||||||
|
l = self.initTree(2*p)
|
||||||
|
r = self.initTree(2*p+1)
|
||||||
|
if self.win(r,l):
|
||||||
|
self.tree[p] = l
|
||||||
|
self.dir = 'r'
|
||||||
|
return r
|
||||||
|
else :
|
||||||
|
self.tree[p] = r
|
||||||
|
self.dir = 'l'
|
||||||
|
return l
|
||||||
|
def getWinIdx(self,idx=1):
|
||||||
|
while 2*idx<self.n:
|
||||||
|
idx = 2*idx if self.tree[idx].dir == 'l' else idx*2+1
|
||||||
|
return self.treeToArray(idx)
|
||||||
|
def winner(self):
|
||||||
|
i = self.getWinIdx()
|
||||||
|
i = i+1 if self.players[i] !=self.tree[0] else i
|
||||||
|
return self.tree[0],i
|
||||||
|
def getOppo(self,i,x,p):
|
||||||
|
oppo=None
|
||||||
|
if 2*p<self.n:oppo=self.tree[2*p]
|
||||||
|
elif i<=self.lowExt:oppo=self.players[i-1+i%2*2]
|
||||||
|
else:
|
||||||
|
lpl= self.players[2*p+self.lowExt-self.n+1]
|
||||||
|
oppo = lpl if lpl!=x else self.players[2*p+self.lowExt-self.n+2]
|
||||||
|
return oppo
|
||||||
|
def update(self,i,x):
|
||||||
|
''' i is 1-indexed which is the num of player
|
||||||
|
and x is the new val of the player '''
|
||||||
|
self.players[i]=x
|
||||||
|
p = self.arrayToTree(i)
|
||||||
|
oppo =self.getOppo(i,x,p)
|
||||||
|
self.tree[p],winner = x , oppo if self.win(oppo,x) else oppo,x
|
||||||
|
p=p//2
|
||||||
|
while p:
|
||||||
|
l = self.tree[p*2]
|
||||||
|
r = None
|
||||||
|
if 2*p+1<self.n:r=self.tree[p*2+1] #notice this !!!
|
||||||
|
else:r = self.players[2*p+self.lowExt-self.n+1]
|
||||||
|
self.tree[p] = l if self.win(l,r) else r
|
||||||
|
p=p//2
|
||||||
|
# to do update-func the change of every node's dir and loser
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
s= [4,1,6,7,9,5234,0,2,7,4,123]
|
||||||
|
t = winnerTree(s)
|
||||||
|
for i in s:
|
||||||
|
val,idx=t.winner()
|
||||||
|
print(val,idx)
|
||||||
|
t.update(idx,-1)
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
[0, 4, 1, 6, 7, 9, 5234, 0, 2, 123] [0, 5234, 9, 5234, 6, 9, 5234, 123, 4]
|
||||||
|
5234 6
|
||||||
|
123 9
|
||||||
|
9 5
|
||||||
|
7 4
|
||||||
|
6 3
|
||||||
|
4 1
|
||||||
|
2 8
|
||||||
|
1 2
|
||||||
|
0 7
|
||||||
|
-1 1
|
||||||
|
'''
|
138
codes/dataStructure/map/map.cc
Normal file
138
codes/dataStructure/map/map.cc
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
#include<stdio.h>
|
||||||
|
bool isZero(float a)
|
||||||
|
{
|
||||||
|
return a<0.00001&&-a<0.00001;
|
||||||
|
}
|
||||||
|
template<class,class> class map;
|
||||||
|
//notice that if you declare a class template,declare the class first like this.
|
||||||
|
template<class t1,class t2>
|
||||||
|
class pair
|
||||||
|
{
|
||||||
|
friend class map<t1,t2>;
|
||||||
|
pair<t1,t2> *next;
|
||||||
|
public:
|
||||||
|
t1 first;
|
||||||
|
t2 second;
|
||||||
|
|
||||||
|
};
|
||||||
|
template<class t1,class t2>
|
||||||
|
class map
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
pair<t1,t2> head;
|
||||||
|
int cur;
|
||||||
|
pair<t1,t2> *last_visit;
|
||||||
|
public:
|
||||||
|
map();
|
||||||
|
~map();
|
||||||
|
bool has(t1);
|
||||||
|
void erase(t1);
|
||||||
|
t2& operator[](t1);
|
||||||
|
pair<t1,t2> &locate(int index = -1);
|
||||||
|
int size();
|
||||||
|
};
|
||||||
|
template<class t1,class t2>
|
||||||
|
map<t1,t2>::map(){
|
||||||
|
n=0;
|
||||||
|
cur=-1;
|
||||||
|
last_visit= &head;
|
||||||
|
head.next=NULL;
|
||||||
|
head.first = head.second = 0;
|
||||||
|
}
|
||||||
|
template<class t1,class t2>
|
||||||
|
map<t1,t2>::~map()
|
||||||
|
{
|
||||||
|
pair<t1,t2> *p,*q=&head;
|
||||||
|
while(q!=NULL){
|
||||||
|
p=q->next;
|
||||||
|
delete q;
|
||||||
|
q=p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class t1,class t2>
|
||||||
|
bool map<t1,t2>::has(t1 key)
|
||||||
|
{
|
||||||
|
pair<t1,t2> *p = head.next;
|
||||||
|
for(int i = 0;i<n&&p->first<=key;++i){
|
||||||
|
if(isZero(p->first-key)) return 1;
|
||||||
|
p=p->next;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
template<class t1,class t2>
|
||||||
|
pair<t1,t2>& map<t1,t2>::locate(int index)
|
||||||
|
{
|
||||||
|
if(index>=n||index<0){
|
||||||
|
printf("the index is out of range\n");
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
if(cur>index){
|
||||||
|
last_visit = &head;
|
||||||
|
cur = -1;
|
||||||
|
}
|
||||||
|
while(cur<index){
|
||||||
|
last_visit = last_visit->next;
|
||||||
|
++cur;
|
||||||
|
}
|
||||||
|
return *last_visit;
|
||||||
|
}
|
||||||
|
template<class t1,class t2>
|
||||||
|
int map<t1,t2>::size()
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
template<class t1,class t2>
|
||||||
|
t2& map<t1,t2>::operator[](t1 key)
|
||||||
|
{
|
||||||
|
pair<t1,t2> * p=&head;
|
||||||
|
while(p->next!=NULL){
|
||||||
|
if(isZero(p->next->first-key)) return p->next->second;
|
||||||
|
else if(p->next->first>key){break;}
|
||||||
|
p=p->next;
|
||||||
|
}
|
||||||
|
cur=-1;
|
||||||
|
last_visit= &head;
|
||||||
|
pair<t1,t2> *tmp = new pair<t1,t2>;
|
||||||
|
tmp ->next = p->next;
|
||||||
|
tmp->first = key;
|
||||||
|
p->next = tmp;
|
||||||
|
++n;
|
||||||
|
return tmp->second;
|
||||||
|
}
|
||||||
|
template<class t1,class t2>
|
||||||
|
void map<t1,t2>::erase(t1 key)
|
||||||
|
{
|
||||||
|
pair<t1,t2> *p = &head;
|
||||||
|
while(p->next!=NULL){
|
||||||
|
if(isZero(p->next->first-key)){
|
||||||
|
pair<t1,t2> *q = p->next;
|
||||||
|
p->next = p->next->next;
|
||||||
|
delete q;
|
||||||
|
--n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p=p->next;
|
||||||
|
}
|
||||||
|
cur=-1;
|
||||||
|
last_visit= &head;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
map<double,float> b;
|
||||||
|
for(int i = 0;i<40;++i){
|
||||||
|
b[i] = i;
|
||||||
|
if(i%3){
|
||||||
|
b[i] = 1;
|
||||||
|
}
|
||||||
|
if(i%2){
|
||||||
|
b.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
for(int i = 0;i<b.size();++i){
|
||||||
|
printf("item %d %g:%g\n",i,b.locate(i).first,b.locate(i).second);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
codes/dataStructure/map/map.exe
Normal file
BIN
codes/dataStructure/map/map.exe
Normal file
Binary file not shown.
Binary file not shown.
143
codes/dataStructure/navigation/directed.py
Normal file
143
codes/dataStructure/navigation/directed.py
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
from collections import deque
|
||||||
|
class vertex:
|
||||||
|
def __init__(self,mark,val=None ,firstEdge = None):
|
||||||
|
self.mark = mark
|
||||||
|
self.val = val
|
||||||
|
self.firstEdge = firstEdge
|
||||||
|
self.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
try:
|
||||||
|
int(self.mark)
|
||||||
|
return 'v'+str(self.mark)
|
||||||
|
except:return str(self.mark)
|
||||||
|
def __repr__(self):
|
||||||
|
li=[]
|
||||||
|
arc= self.firstEdge
|
||||||
|
while arc!=None:
|
||||||
|
li.append(arc)
|
||||||
|
arc= arc.outNextEdge
|
||||||
|
return str(self)+ ' to:'+str([str(i.inArrow) for i in li])
|
||||||
|
class edge:
|
||||||
|
def __init__(self,outArrow,inArrow,outNextEdge = None,inNextEdge = None, weight = 1):
|
||||||
|
self.weight = weight
|
||||||
|
self.inNextEdge = inNextEdge
|
||||||
|
self.outNextEdge = outNextEdge
|
||||||
|
self.outArrow = outArrow
|
||||||
|
self.inArrow=inArrow
|
||||||
|
self.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
return '--'+str(self.weight)+'-->'
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
class graph:
|
||||||
|
def __init__(self):
|
||||||
|
self.vertexs = {}
|
||||||
|
self.edges = {}
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.vertexs[i]
|
||||||
|
def __setitem__(selfi,x):
|
||||||
|
self.vertexs[i]= x
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.vertexs.values())
|
||||||
|
def __bool__(self):
|
||||||
|
return len(self.vertexs)!=0
|
||||||
|
def addVertex(self,i):
|
||||||
|
if not (i,vertex) and i not in self.vertexs:self.vertexs[i]= vertex(i)
|
||||||
|
if isinstance(i,vertex) and i not in self.vertexs:self.vertexs[i.mark]= i
|
||||||
|
def isConnected(self,v,u):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
arc= v.firstEdge
|
||||||
|
while arc!=None:
|
||||||
|
if arc.inArrow==u:return True
|
||||||
|
arc = arc.inNextEdge
|
||||||
|
return False
|
||||||
|
def __getVertex(self,v):
|
||||||
|
if not isinstance(v,vertex):
|
||||||
|
if v not in self.vertexs:
|
||||||
|
self.vertexs[v]=vertex(v)
|
||||||
|
return self.vertexs[v]
|
||||||
|
return v
|
||||||
|
def addEdge(self,v,u,weight = 1):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
arc = v.firstEdge
|
||||||
|
while arc!=None: #examine that if v,u have been already connected
|
||||||
|
if arc.inArrow==u: return
|
||||||
|
arc= arc.outNextEdge
|
||||||
|
newEdge = edge(v,u,v.firstEdge,u.firstEdge,weight)
|
||||||
|
self.edges[(v.mark,u.mark)] = newEdge
|
||||||
|
v.firstEdge = newEdge
|
||||||
|
def delEdge(self,v,u):
|
||||||
|
if not isinstance(v,vertex):v= self.vertexs[v]
|
||||||
|
if not isinstance(u,vertex):u= self.vertexs[u]
|
||||||
|
self._unrelated(v,u)
|
||||||
|
del self.edges[(v.mark,u.mark)]
|
||||||
|
def _unrelated(self,v,u):
|
||||||
|
if v.firstEdge==None:return
|
||||||
|
if v.firstEdge.inArrow == u:
|
||||||
|
v.firstEdge =v.firstEdge.outNextEdge
|
||||||
|
else:
|
||||||
|
arc = v.firstEdge
|
||||||
|
while arc.outNextEdge!=None:
|
||||||
|
if arc.outNextEdge.inArrow ==u:
|
||||||
|
arc.outNextEdge = arc.outNextEdge.outNextEdge
|
||||||
|
break
|
||||||
|
def reVisit(self):
|
||||||
|
for i in self.vertexs:
|
||||||
|
self.vertexs[i].isVisited=False
|
||||||
|
for i in self.edges:
|
||||||
|
self.edges[i].isVisited=False
|
||||||
|
def __str__(self):
|
||||||
|
arcs= list(self.edges.keys())
|
||||||
|
arcs=[str(i[0])+'--->'+str(i[1])+' weight:'+str(self.edges[i].weight) for i in arcs]
|
||||||
|
s= '\n'.join(arcs)
|
||||||
|
return s
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
def notIn(self,v):
|
||||||
|
if (isinstance(v,vertex) and v.mark not in self.vertexs) or v not in self.vertexs:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
def minPath(self,v,u):
|
||||||
|
'''dijstra'''
|
||||||
|
self.reVisit()
|
||||||
|
if self.notIn(v) or self.notIn(u):
|
||||||
|
return [],0
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
if v.firstEdge==None:return [],0
|
||||||
|
q=deque([v])
|
||||||
|
last = {i : None for i in self}
|
||||||
|
distance={i : 1<<30 for i in self}
|
||||||
|
distance[v]=0
|
||||||
|
while len(q)!=0:
|
||||||
|
cur= q.popleft()
|
||||||
|
cur.isVisited = True
|
||||||
|
arc = cur.firstEdge
|
||||||
|
while arc!=None:
|
||||||
|
to = arc.inArrow
|
||||||
|
if not to.isVisited:
|
||||||
|
q.append(to)
|
||||||
|
if distance [to] > distance[cur]+arc.weight:
|
||||||
|
last[to]=cur
|
||||||
|
distance[to] =distance[cur]+arc.weight
|
||||||
|
arc= arc.outNextEdge
|
||||||
|
cur = u
|
||||||
|
path=[]
|
||||||
|
while cur!=None and cur!=v:
|
||||||
|
path.append(cur.mark)
|
||||||
|
cur=last[cur]
|
||||||
|
if cur==None:return [], 0
|
||||||
|
path.append(v.mark)
|
||||||
|
return path[::-1],distance[u]
|
||||||
|
def hasVertex(self,mark):
|
||||||
|
return mark in self.vertexs
|
||||||
|
def display(self):
|
||||||
|
print('vertexs')
|
||||||
|
for i in self.vertexs:
|
||||||
|
print(self.vertexs[i].__repr__())
|
||||||
|
print('edges')
|
||||||
|
for i in self.edges:
|
||||||
|
arc=self.edges[i]
|
||||||
|
print(str(arc.outArrow)+str(arc)+str(arc.inArrow))
|
225
codes/dataStructure/navigation/graph.py
Normal file
225
codes/dataStructure/navigation/graph.py
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
from collections import deque
|
||||||
|
import directed
|
||||||
|
class vertex:
|
||||||
|
def __init__(self,mark,val=None):
|
||||||
|
self.mark = mark
|
||||||
|
self.val = val
|
||||||
|
self.edges = {}
|
||||||
|
self.isVisited = False
|
||||||
|
def __getitem__(self,adjVertexMark):
|
||||||
|
return self.edges[adjVertexMark]
|
||||||
|
def __delitem__(self,k):
|
||||||
|
del self.edges[k]
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.edges.values())
|
||||||
|
def __str__(self):
|
||||||
|
try:
|
||||||
|
int(self.mark)
|
||||||
|
return 'v'+str(self.mark)
|
||||||
|
except:return str(self.mark)
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
class edge:
|
||||||
|
def __init__(self,adjVertexs, weight = 1):
|
||||||
|
'''adjVertexs:tuple(v.mark,u.mark)'''
|
||||||
|
self.weight = weight
|
||||||
|
self.adjVertexs = adjVertexs
|
||||||
|
self.isVisted = False
|
||||||
|
def __add__(self,x):
|
||||||
|
return self.weight +x
|
||||||
|
def __radd__(self,x):
|
||||||
|
return self+x
|
||||||
|
def __getitem__(self,k):
|
||||||
|
if k!=0 or k!=1:raise IndexError
|
||||||
|
return self.adjVertexs[k]
|
||||||
|
def __str__(self):
|
||||||
|
return '--'+str(self.weight)+'--'
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
@property
|
||||||
|
def v(self):
|
||||||
|
return self.adjVertexs[0]
|
||||||
|
@property
|
||||||
|
def u(self):
|
||||||
|
return self.adjVertexs[1]
|
||||||
|
class graph:
|
||||||
|
def __init__(self):
|
||||||
|
self.vertexs = {}
|
||||||
|
self.edges = {}
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.vertexs[i]
|
||||||
|
def __setitem__(selfi,x):
|
||||||
|
self.vertexs[i]= x
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.vertexs)
|
||||||
|
def __bool__(self):
|
||||||
|
return len(self.vertexs)!=0
|
||||||
|
def addVertex(self,v):
|
||||||
|
if not isinstance(v,vertex) and v not in self.vertexs:self.vertexs[v]= vertex(v)
|
||||||
|
if isinstance(v,vertex) and v not in self.vertexs:self.vertexs[v.mark]= v
|
||||||
|
|
||||||
|
def __getVertex(self,v):
|
||||||
|
if not isinstance(v,vertex):
|
||||||
|
if v not in self.vertexs:
|
||||||
|
self.vertexs[v]=vertex(v)
|
||||||
|
return self.vertexs[v]
|
||||||
|
return v
|
||||||
|
def addEdge(self,v,u,weight = 1):
|
||||||
|
v = self.__getVertex(v)
|
||||||
|
u = self.__getVertex(u)
|
||||||
|
for arc in v:
|
||||||
|
if u in arc.adjVertexs:return #examine that if v,u have been already connected
|
||||||
|
vertexs = (v,u)
|
||||||
|
newEdge = edge (vertexs,weight)
|
||||||
|
self.edges[vertexs] = newEdge
|
||||||
|
v.edges[u] = newEdge
|
||||||
|
u.edges[v] = newEdge
|
||||||
|
def delEdge(self,v,u):
|
||||||
|
if not isinstance(v,vertex):v= self.vertexs[v]
|
||||||
|
if not isinstance(u,vertex):u= self.vertexs[u]
|
||||||
|
try:
|
||||||
|
del v[u]
|
||||||
|
del u[v]
|
||||||
|
except:print("error!"+str(v)+','+str(u)+' arent adjacent now')
|
||||||
|
del self.edges[(v,u)]
|
||||||
|
def reVisit(self):
|
||||||
|
for i in self.vertexs.values():
|
||||||
|
i.isVisited = False
|
||||||
|
for i in self.edges.values():
|
||||||
|
i.isVisited = False
|
||||||
|
def __str__(self):
|
||||||
|
arcs= list(self.edges.keys())
|
||||||
|
arcs=[str(i[0])+str(self.edges[i])+str(i[1]) for i in arcs]
|
||||||
|
s= '\n'.join(arcs)
|
||||||
|
return s
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
def minPath(self,v,u):
|
||||||
|
self.reVisit()
|
||||||
|
v=self.__getVertex(v)
|
||||||
|
u=self.__getVertex(u)
|
||||||
|
q=deque([v])
|
||||||
|
last={i:None for i in self.vertexs.values()}
|
||||||
|
last[v] = 0
|
||||||
|
ds={i:1<<30 for i in self.vertexs.values()}
|
||||||
|
ds[v]=0
|
||||||
|
while len(q)!=0:
|
||||||
|
nd = q.popleft()
|
||||||
|
nd.isVisited=True
|
||||||
|
for edge in nd:
|
||||||
|
tgt=None
|
||||||
|
if edge.v==nd:
|
||||||
|
tgt = edge.u
|
||||||
|
else:tgt = edge.v
|
||||||
|
tmp=ds[nd]+edge
|
||||||
|
if ds[tgt] >tmp:
|
||||||
|
ds[tgt]=tmp
|
||||||
|
last[tgt] = nd
|
||||||
|
if not tgt.isVisited:q.append(tgt)
|
||||||
|
path=[]
|
||||||
|
cur = u
|
||||||
|
while cur !=None and cur.mark!=v.mark:
|
||||||
|
path.append(cur.mark)
|
||||||
|
cur = last[cur]
|
||||||
|
if cur==None:return [],-1
|
||||||
|
path.append(v.mark)
|
||||||
|
return path[::-1],ds[u]
|
||||||
|
def hasCircle(self):
|
||||||
|
pass
|
||||||
|
def display(self):
|
||||||
|
print('vertexs')
|
||||||
|
for i in self.vertexs:
|
||||||
|
print(i,end=' ')
|
||||||
|
print('')
|
||||||
|
print('edges')
|
||||||
|
for i in self.edges:
|
||||||
|
arc=self.edges[i]
|
||||||
|
print(str(arc.v)+str(arc)+str(arc.u))
|
||||||
|
|
||||||
|
def loop(dic):
|
||||||
|
while True:
|
||||||
|
print('input vertexs to get the min distance, input \'exit\' to exit')
|
||||||
|
s=input().strip()
|
||||||
|
if s=='exit':break
|
||||||
|
s=s.split(' ')
|
||||||
|
s=[dic[i] if '0'<=i[0]<='9' else i for i in s]
|
||||||
|
a,b,c=s[0],s[1],None
|
||||||
|
path,d = g.minPath(a,b)
|
||||||
|
path2=None
|
||||||
|
if len(s)==3:
|
||||||
|
c=s[2]
|
||||||
|
path2,d2=g.minPath(b,c)
|
||||||
|
d+=d2
|
||||||
|
if path==[] or path2==[] :
|
||||||
|
if len(s)==3: print(a+' can\'t reach '+c+' via '+b)
|
||||||
|
else: print(a+' can\'t reach '+b)
|
||||||
|
continue
|
||||||
|
if path2!=None:path+=path2[1:]
|
||||||
|
print('distance : ',d)
|
||||||
|
print('path','-->'.join(path))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
s=input('1. undireted\n2. directed\n')
|
||||||
|
flag=input('name vertex by 1. num(1-index) or 2. string? ').strip()
|
||||||
|
dic={}
|
||||||
|
g = graph()
|
||||||
|
if s=='2': g=directed.graph()
|
||||||
|
v,e=input('input vertex num & edge num: ').strip().split(' ')
|
||||||
|
v,e=int(v),int(e)
|
||||||
|
if flag=='1':
|
||||||
|
for i in range(v):
|
||||||
|
tmp=str(i+1)
|
||||||
|
dic[tmp]=tmp
|
||||||
|
g.addVertex(tmp)
|
||||||
|
else:
|
||||||
|
print('input vertex name line by line')
|
||||||
|
for i in range(v):
|
||||||
|
dic[str(i+1)]=input().strip()
|
||||||
|
g.addVertex(dic[str(i+1)])
|
||||||
|
print('input edge info line by line')
|
||||||
|
for i in range(e):
|
||||||
|
li=input().strip().split(' ')
|
||||||
|
a,b,w=li[0],li[1],1
|
||||||
|
if len(li)==3:w=int(li[2])
|
||||||
|
a,b=dic[a],dic[b]
|
||||||
|
g.addEdge(a,b,w)
|
||||||
|
print('you\'ve build graph :')
|
||||||
|
g.display()
|
||||||
|
loop(dic)
|
||||||
|
'''
|
||||||
|
6 6
|
||||||
|
1 2 5
|
||||||
|
1 3 1
|
||||||
|
2 6 1
|
||||||
|
2 5 1
|
||||||
|
4 5 2
|
||||||
|
3 4 1
|
||||||
|
1 5
|
||||||
|
'''
|
||||||
|
|
||||||
|
'''
|
||||||
|
6 10
|
||||||
|
NewYork
|
||||||
|
LA
|
||||||
|
BeiJing
|
||||||
|
HeFei
|
||||||
|
SiChuan
|
||||||
|
Paris
|
||||||
|
2 1
|
||||||
|
5 3
|
||||||
|
6 1
|
||||||
|
3 1
|
||||||
|
4 4
|
||||||
|
1 3
|
||||||
|
2 1
|
||||||
|
5 1
|
||||||
|
2 4
|
||||||
|
3 4
|
||||||
|
SiChuan NewYork
|
||||||
|
Paris HeFei
|
||||||
|
V4<---V3<---V2<---V1
|
||||||
|
3
|
||||||
|
V4<---V3<---V2
|
||||||
|
2
|
||||||
|
'''
|
BIN
codes/dataStructure/navigation/lab4_朱河勤_PB16030899.zip
Normal file
BIN
codes/dataStructure/navigation/lab4_朱河勤_PB16030899.zip
Normal file
Binary file not shown.
327
codes/dataStructure/polynomial/polynomial.cpp
Normal file
327
codes/dataStructure/polynomial/polynomial.cpp
Normal file
|
@ -0,0 +1,327 @@
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<string.h>
|
||||||
|
#include<math.h>
|
||||||
|
#include<malloc.h>
|
||||||
|
#include<map>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool isZero(double a)
|
||||||
|
{
|
||||||
|
if((a<0.00001)&&-a<0.00001)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
class node
|
||||||
|
{
|
||||||
|
friend class polynomial;
|
||||||
|
double coefficient;
|
||||||
|
double index;
|
||||||
|
};
|
||||||
|
class polynomial
|
||||||
|
{
|
||||||
|
int SIZE;
|
||||||
|
int n;
|
||||||
|
node* p;
|
||||||
|
public:
|
||||||
|
polynomial(int sz=50);
|
||||||
|
polynomial(const polynomial & );
|
||||||
|
~polynomial();
|
||||||
|
double cal(double);
|
||||||
|
void getData();
|
||||||
|
void display();
|
||||||
|
polynomial operator=(const polynomial &);
|
||||||
|
polynomial operator+(const polynomial &);
|
||||||
|
polynomial operator-(const polynomial &);
|
||||||
|
polynomial operator*(const polynomial &);
|
||||||
|
};
|
||||||
|
polynomial::polynomial(int sz):n(0),SIZE(sz)
|
||||||
|
{
|
||||||
|
p = (node*) new node[SIZE];
|
||||||
|
memset(p,0,sizeof(p));
|
||||||
|
}
|
||||||
|
polynomial::~polynomial()
|
||||||
|
{
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
double polynomial::cal(double x)
|
||||||
|
{
|
||||||
|
double rst=0;
|
||||||
|
for(int i =0;i<n;++i){
|
||||||
|
rst += pow(x,p[i].index)*p[i].coefficient;
|
||||||
|
}
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
|
polynomial::polynomial(const polynomial &a)
|
||||||
|
{
|
||||||
|
p = (node*) new node[50];
|
||||||
|
memset(p,0,sizeof(p));
|
||||||
|
n = a.n;
|
||||||
|
for(int i = 0;i<a.n;++i){
|
||||||
|
p[i].index = a.p[i].index;
|
||||||
|
p[i].coefficient = a.p[i].coefficient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
polynomial polynomial::operator=(const polynomial& a)
|
||||||
|
{
|
||||||
|
n = a.n;
|
||||||
|
for(int i = 0;i<a.n;++i){
|
||||||
|
p[i].index = a.p[i].index;
|
||||||
|
p[i].coefficient = a.p[i].coefficient;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
void polynomial::display()
|
||||||
|
{
|
||||||
|
node * tmp = p;
|
||||||
|
if(n == 0){
|
||||||
|
printf("0\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// char *fmt = ("x"); printf(fmt,...);
|
||||||
|
for(int i = n-1;i>=0;--i){
|
||||||
|
double t = tmp[i].coefficient;
|
||||||
|
double idx = tmp[i].index;
|
||||||
|
if(isZero(idx)){
|
||||||
|
printf("%+g",t);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(isZero(t-1)) printf("+");
|
||||||
|
else if(isZero(t+1))printf("-");
|
||||||
|
else printf("%+g",t);
|
||||||
|
printf("x");
|
||||||
|
if(!isZero(idx-1)) printf("^%g",idx);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
void polynomial::getData()
|
||||||
|
{
|
||||||
|
printf("Please input data . \n");
|
||||||
|
printf("For every item,Coefficient first .Use space to separate,EOF to end\n");
|
||||||
|
map<double,double> mp;
|
||||||
|
double idx;
|
||||||
|
double coef;
|
||||||
|
while(scanf("%lf%lf",&coef,&idx)!=EOF){
|
||||||
|
if(isZero(coef)) continue;
|
||||||
|
if(mp.count(idx) == 0){
|
||||||
|
mp[idx] = coef;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mp[idx] += coef;
|
||||||
|
if(isZero(mp[idx])){
|
||||||
|
mp.erase(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(mp.size()>SIZE){
|
||||||
|
SIZE *=2;
|
||||||
|
p = (node*)realloc(p,sizeof(node)*SIZE) ;
|
||||||
|
}
|
||||||
|
for(map<double,double>::iterator it = mp.begin();it!=mp.end();++it){
|
||||||
|
p[n].index = it->first;
|
||||||
|
p[n++].coefficient = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
polynomial polynomial::operator+(const polynomial & a)
|
||||||
|
{
|
||||||
|
polynomial rst ;
|
||||||
|
int p1 = 0,p2 = 0,p3 = 0;
|
||||||
|
double exp1 = p[p1].index;
|
||||||
|
double exp2 = a.p[p2].index;
|
||||||
|
while(p1<n && p2<a.n){
|
||||||
|
while(p1<n &&exp1<exp2){
|
||||||
|
rst.p[p3].index = exp1;
|
||||||
|
rst.p[p3].coefficient = p[p1].coefficient;
|
||||||
|
++p1,++p3;
|
||||||
|
exp1 = p[p1].index;;
|
||||||
|
}
|
||||||
|
while(p2<a.n &&exp1>exp2){
|
||||||
|
rst.p[p3].index = exp2;
|
||||||
|
rst.p[p3].coefficient = a.p[p2].coefficient;
|
||||||
|
++p2,++p3;
|
||||||
|
exp2 = a.p[p2].index;;
|
||||||
|
}
|
||||||
|
if(isZero(exp1-exp2)){
|
||||||
|
double tmp= p[p1].coefficient + a.p[p2].coefficient;
|
||||||
|
if(isZero(tmp)){
|
||||||
|
++p1,++p2;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rst.p[p3].index = p[p1].index;
|
||||||
|
rst.p[p3].coefficient = tmp;
|
||||||
|
++p1,++p2,++p3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(p1 == n){
|
||||||
|
while(p2<a.n){
|
||||||
|
rst.p[p3].index = a.p[p2].index;
|
||||||
|
rst.p[p3].coefficient = a.p[p2].coefficient;
|
||||||
|
++p2,++p3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
while(p1<n){
|
||||||
|
rst.p[p3].index = p[p1].index;
|
||||||
|
rst.p[p3].coefficient = p[p1].coefficient;
|
||||||
|
++p1,++p3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rst.n = p3;
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
|
polynomial polynomial::operator-(const polynomial & a)
|
||||||
|
{
|
||||||
|
polynomial rst(a) ;
|
||||||
|
int i = 0;
|
||||||
|
while(i<rst.n){
|
||||||
|
rst.p[i].coefficient = -rst.p[i].coefficient;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return (*this + rst);
|
||||||
|
}
|
||||||
|
polynomial polynomial::operator*(const polynomial & a)
|
||||||
|
{
|
||||||
|
map<double,double> mp;
|
||||||
|
for(int i = 0;i<n;++i){
|
||||||
|
double idx = p[i].index;
|
||||||
|
double coef = p[i].coefficient;
|
||||||
|
for(int j = 0;j<a.n;++j){
|
||||||
|
double index = idx+a.p[j].index;
|
||||||
|
if(mp.count(index)==0){
|
||||||
|
mp[index] = coef*a.p[j].coefficient;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mp[index] += coef*a.p[j].coefficient;
|
||||||
|
if(isZero(mp[index])){
|
||||||
|
mp.erase(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sz =50;
|
||||||
|
while(mp.size()>sz){
|
||||||
|
sz *=2;
|
||||||
|
}
|
||||||
|
polynomial rst(sz);
|
||||||
|
for(map<double,double>::iterator it = mp.begin();it!=mp.end();++it){
|
||||||
|
rst.p[rst.n].index = it->first;
|
||||||
|
rst.p[rst.n++].coefficient = it->second;
|
||||||
|
}
|
||||||
|
return rst;
|
||||||
|
}
|
||||||
|
int num = 0;
|
||||||
|
polynomial pl[30];
|
||||||
|
void menu()
|
||||||
|
{
|
||||||
|
printf("**********OPERATIONS***********\n");
|
||||||
|
printf("*****0. create *****\n");
|
||||||
|
printf("*****1. add + *****\n");
|
||||||
|
printf("*****2. sub - *****\n");
|
||||||
|
printf("*****3. mul * *****\n");
|
||||||
|
printf("*****4. display *****\n");
|
||||||
|
printf("*****5. menu *****\n");
|
||||||
|
printf("*****6. clear screen *****\n");
|
||||||
|
printf("*****7. exit *****\n");
|
||||||
|
printf("*****8. copy *****\n");
|
||||||
|
printf("*****9. display all *****\n");
|
||||||
|
printf("*****10. cal val *****\n");
|
||||||
|
printf("**********OPERATIONS***********\n");
|
||||||
|
}
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
int op;
|
||||||
|
while(scanf("%d",&op)!=EOF){
|
||||||
|
if(op == 0){
|
||||||
|
pl[num].getData();
|
||||||
|
++num;
|
||||||
|
printf("You've created polynomial %d:\n",num);
|
||||||
|
pl[num-1].display();
|
||||||
|
}
|
||||||
|
else if(op==1||op==2||op==3){
|
||||||
|
if(num<2){
|
||||||
|
printf("Oops! you've got less two polynomial\nPlease choose another operation\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf("input two nums of the two polynomial to be operated.eg: 1 2\n");
|
||||||
|
int t1=100,t2=100;
|
||||||
|
while(1){
|
||||||
|
scanf("%d%d",&t1,&t2);
|
||||||
|
if(t1>num||t2>num||t1<0||t2<0){
|
||||||
|
printf("wrong num ,please input again\n");
|
||||||
|
}
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
printf("the rst is:\n");
|
||||||
|
t1 -=1,t2-=1;
|
||||||
|
if(op == 1){
|
||||||
|
(pl[t1]+pl[t2]).display();
|
||||||
|
}
|
||||||
|
else if(op == 2){
|
||||||
|
(pl[t1]-pl[t2]).display();
|
||||||
|
}
|
||||||
|
else (pl[t1]*pl[t2]).display();
|
||||||
|
}
|
||||||
|
else if(op == 4){
|
||||||
|
printf("input a polynomial's num to display it\n");
|
||||||
|
int tmp;
|
||||||
|
scanf("%d",&tmp);
|
||||||
|
if(tmp>num){
|
||||||
|
printf("wrong num");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
printf("info of polynomial %d\n",tmp);
|
||||||
|
pl[tmp-1].display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(op == 9){
|
||||||
|
for(int i = 0;i<num;++i){
|
||||||
|
printf("polynomial %d : ",i+1);
|
||||||
|
pl[i].display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(op == 5){
|
||||||
|
menu();
|
||||||
|
}
|
||||||
|
else if(op == 6){
|
||||||
|
system("cls");
|
||||||
|
menu();
|
||||||
|
}
|
||||||
|
else if(op == 10){
|
||||||
|
double x;
|
||||||
|
int t;
|
||||||
|
printf("choose a polynomial\n");
|
||||||
|
scanf("%d",&t);
|
||||||
|
if(t>num||t<0){
|
||||||
|
printf("wrong num\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("input a value\n");
|
||||||
|
scanf("%lf",&x);
|
||||||
|
pl[t-1].display();
|
||||||
|
printf("%g\n",pl[t-1].cal(x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(op == 8){
|
||||||
|
if(num == 0){
|
||||||
|
printf("you have'nt any polynomial tp copy\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int n = num+1;
|
||||||
|
while(n>num){
|
||||||
|
printf("input the number of an existing polynomial you want to copy\n");
|
||||||
|
scanf("%d",&n);
|
||||||
|
}
|
||||||
|
(pl[num] = pl[n-1]);
|
||||||
|
printf("You've copyed this polynomial:\n");
|
||||||
|
pl[num++].display();
|
||||||
|
}
|
||||||
|
else exit(0);
|
||||||
|
printf("select an operation\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
menu();
|
||||||
|
loop();
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
codes/dataStructure/polynomial/polynomial.exe
Normal file
BIN
codes/dataStructure/polynomial/polynomial.exe
Normal file
Binary file not shown.
161
codes/dataStructure/polynomial/polynomial.py
Normal file
161
codes/dataStructure/polynomial/polynomial.py
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
#!/bin/python3
|
||||||
|
# notice that creating a class's initialization won't conflict with __call__ method
|
||||||
|
# because the former call class ,and the latter call instance
|
||||||
|
|
||||||
|
# to be implemented
|
||||||
|
|
||||||
|
class polynomial:
|
||||||
|
pls= []
|
||||||
|
n = 0
|
||||||
|
def dictize(pl):
|
||||||
|
if isinstance(pl,int) or isinstance(pl,float):
|
||||||
|
pl = {0:pl}
|
||||||
|
if isinstance(pl,polynomial):
|
||||||
|
pl = pl.polynomial.copy()
|
||||||
|
return pl
|
||||||
|
def isZero(n):
|
||||||
|
return abs(n)<0.000001
|
||||||
|
def __init__(self,s='0 0'):
|
||||||
|
polynomial.pls.append(self)
|
||||||
|
polynomial.n +=1
|
||||||
|
if isinstance(s,polynomial):
|
||||||
|
self.polynomial=s.polynomial.copy()
|
||||||
|
# don't write like this .**self.polynomial = s.polynomial**,it's ref
|
||||||
|
return
|
||||||
|
elif isinstance(s,dict):
|
||||||
|
self.polynomial = s.copy()
|
||||||
|
return
|
||||||
|
s= s.replace(',',' ')
|
||||||
|
s= s.replace('x',' ')
|
||||||
|
s= s.replace('x^',' ')
|
||||||
|
s = s.replace(':',' ')
|
||||||
|
s = s.replace('\n',' ')
|
||||||
|
s = s.split(' ')
|
||||||
|
num = len(s)
|
||||||
|
i = 0
|
||||||
|
print(s)
|
||||||
|
self.polynomial = dict()
|
||||||
|
li = [float(i) for i in s]
|
||||||
|
while i<num:
|
||||||
|
if not polynomial.isZero(li[i]):
|
||||||
|
index = li[i+1]
|
||||||
|
if index in self.polynomial.keys():
|
||||||
|
self.polynomial[index] += li[i]
|
||||||
|
else:self.polynomial[index] = li[i]
|
||||||
|
i+=2
|
||||||
|
if not self.polynomial:
|
||||||
|
self.polynomial = {0:0}
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(list(self.polynomial.keys()))
|
||||||
|
def __getitem__(self,key):
|
||||||
|
return self.polynomial[key]
|
||||||
|
def __setitem__(self,key,val):
|
||||||
|
self.polynomial[key] = val
|
||||||
|
def __delitem__(self,k):
|
||||||
|
del self.polynomial[k]
|
||||||
|
def __add__(self,pl):
|
||||||
|
pl = polynomial.dictize(pl)
|
||||||
|
rst = self.polynomial.copy()
|
||||||
|
for i in pl:
|
||||||
|
if i not in rst:
|
||||||
|
rst[i] = pl[i]
|
||||||
|
else:
|
||||||
|
rst[i] += pl[i]
|
||||||
|
if polynomial.isZero(rst[i]):
|
||||||
|
del rst[i]
|
||||||
|
return polynomial(rst)
|
||||||
|
def __iadd__(self,pl):
|
||||||
|
pl = polynomial.dictize(pl)
|
||||||
|
for i in pl:
|
||||||
|
if i not in self:
|
||||||
|
self[i] = pl[i]
|
||||||
|
else:
|
||||||
|
self[i] += pl[i]
|
||||||
|
if polynomial.isZero(self[i]):
|
||||||
|
del self[i]
|
||||||
|
return self
|
||||||
|
def __sub__(self,pl):
|
||||||
|
pl = polynomial.dictize(pl)
|
||||||
|
tmp = {i:-j for i,j in pl.items()}
|
||||||
|
return self + tmp
|
||||||
|
def __mul__(self,pl):
|
||||||
|
pl = polynomial.dictize(pl)
|
||||||
|
dic = dict()
|
||||||
|
for i in pl:
|
||||||
|
for j in self:
|
||||||
|
index= i+j
|
||||||
|
if index in dic:
|
||||||
|
dic[index] += pl[i]*self[j]
|
||||||
|
else:dic[index] = pl[i]*self[j]
|
||||||
|
return polynomial({i:j for i,j in dic.items() if not polynomial.isZero(j)})
|
||||||
|
def __imul__(self,pl):
|
||||||
|
self = self*pl
|
||||||
|
return self
|
||||||
|
def __pow__(self,n):
|
||||||
|
rst = polynomial({0:1})
|
||||||
|
for i in range(n):
|
||||||
|
rst*=self.polynomial
|
||||||
|
return rst
|
||||||
|
def __repr__(self):
|
||||||
|
return self.__str__()
|
||||||
|
def __str__(self):
|
||||||
|
output = ''
|
||||||
|
if self.polynomial:
|
||||||
|
key = sorted(self.polynomial.keys(),reverse = True)
|
||||||
|
num = len(key)
|
||||||
|
for j,i in enumerate(key):
|
||||||
|
if polynomial.isZero(i):
|
||||||
|
output +='%+g'%self[i]
|
||||||
|
continue
|
||||||
|
if not polynomial.isZero(self[i]-1):
|
||||||
|
if not polynomial.isZero(self[i]+1):
|
||||||
|
output +="%+g"%self[i]
|
||||||
|
else:output +='-'
|
||||||
|
else:output +='+'
|
||||||
|
if not polynomial.isZero(i): output +='x'
|
||||||
|
if not polynomial.isZero(i-1):output +='^%g'%i
|
||||||
|
|
||||||
|
if output[0] == '+':
|
||||||
|
return output[1:]
|
||||||
|
return output
|
||||||
|
def iterPolynomial(self,s):
|
||||||
|
rst = polynomial({0:0})
|
||||||
|
for i in self:
|
||||||
|
rst += s**int(i)*self[i]
|
||||||
|
return rst
|
||||||
|
def __call__(self,s):
|
||||||
|
if isinstance(s,polynomial):
|
||||||
|
return self.iterPolynomial(s)
|
||||||
|
sum = 0
|
||||||
|
for i in self:
|
||||||
|
sum += self[i] * s**i
|
||||||
|
return sum
|
||||||
|
def __xor__(self,n):
|
||||||
|
tmp = polynomial(self)
|
||||||
|
for i in range(n):
|
||||||
|
self = self.iterPolynomial(tmp)
|
||||||
|
return self
|
||||||
|
def save(self):
|
||||||
|
polynomial.pls.append(self)
|
||||||
|
polynomial.n +=1
|
||||||
|
def delPlynomial(self,n):
|
||||||
|
return polynomial.pls.pop(n-1)
|
||||||
|
def menu():
|
||||||
|
print('polynomial operations')
|
||||||
|
print('1.create')
|
||||||
|
print('2.add')
|
||||||
|
print('3.sub')
|
||||||
|
print('4.iadd')
|
||||||
|
print('5.mul')
|
||||||
|
print('6.del')
|
||||||
|
print('7.display')
|
||||||
|
print('8.cal val')
|
||||||
|
print('9.polynomial iter')
|
||||||
|
print('10.menu')
|
||||||
|
print('11.exit')
|
||||||
|
|
||||||
|
def go():
|
||||||
|
menu()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
go()
|
11
codes/dataStructure/primers.py
Normal file
11
codes/dataStructure/primers.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
def get(n)
|
||||||
|
li = [i for i in range(2,n)]
|
||||||
|
i = 1
|
||||||
|
while i <len(li):
|
||||||
|
prod =2 * li[i]
|
||||||
|
while prod <=li[-1]:
|
||||||
|
if prod in li:
|
||||||
|
li.remove(prod)
|
||||||
|
prod+=li[i]
|
||||||
|
i+=1
|
||||||
|
return li
|
43
codes/dataStructure/segTree.cc
Normal file
43
codes/dataStructure/segTree.cc
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include<stdio.h>
|
||||||
|
template<class type>
|
||||||
|
bool operator <(type x,type y){return x<y;}
|
||||||
|
template<class type>
|
||||||
|
class segTree
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
type *p;
|
||||||
|
public:
|
||||||
|
segTree(int n=1);
|
||||||
|
~segTree();
|
||||||
|
void update(int i,type x);
|
||||||
|
type getMin(int a,int b){return find(a,b,1,size,1);}
|
||||||
|
type find(int a,int b,int i,int j,int);
|
||||||
|
};
|
||||||
|
template<class type >
|
||||||
|
segTree<type>::segTree(int n):size(1)
|
||||||
|
{
|
||||||
|
while(size<n)size*=2;
|
||||||
|
p = new type[2*size-1];
|
||||||
|
for (int i=0;i<2*size-1 ;++i )p[i]=MAX;
|
||||||
|
}
|
||||||
|
template<class type >
|
||||||
|
segTree<type>::~segTree(){delete p;}
|
||||||
|
template<class type>
|
||||||
|
void segTree<type>::update(int i,type x)
|
||||||
|
{
|
||||||
|
i+=size-1;
|
||||||
|
p[i]=x;
|
||||||
|
while(i!=0){
|
||||||
|
i/=2;
|
||||||
|
p[i]=p[i*2]<p[i*2+1]?p[i*2]:p[i*2+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class type>
|
||||||
|
type segTree<type>::find(int a,int b,int i , int j,int k)
|
||||||
|
{
|
||||||
|
if(b<i}}j<a)return MAX;// to implement
|
||||||
|
if (a<=i&&j<=b)return p[k];
|
||||||
|
type l= find(a,b,i,(i+j)/2,2*k);
|
||||||
|
type r= find(a,b,(i+j)/2+1,j,2*k+1);
|
||||||
|
return l>r ?l:r;
|
||||||
|
}
|
160
codes/dataStructure/splayTree.py
Normal file
160
codes/dataStructure/splayTree.py
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
from collections import deque,Iterable
|
||||||
|
# use isinstance(obj,Iterable) to judge if an obj is iterable
|
||||||
|
class node:
|
||||||
|
def __init__(self,val = None,left=None,right=None,parent=None):
|
||||||
|
self.val = val
|
||||||
|
if val :self.freq = 1
|
||||||
|
else :self.freq = 0
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
self.parent = parent
|
||||||
|
def getChild(self,s=0):
|
||||||
|
if isinstance(s,int):s =[s]
|
||||||
|
last = self
|
||||||
|
for i in s:
|
||||||
|
if not last:return None
|
||||||
|
if i == 0: last = last.left
|
||||||
|
else:last = last.right
|
||||||
|
return last
|
||||||
|
def setChild(self,child,s=0):
|
||||||
|
if isinstance(s,Iterable):
|
||||||
|
i = s[0]
|
||||||
|
del s[0]
|
||||||
|
if i == 0:self.left.setChild(child,s)
|
||||||
|
else:self.right.setChild(child,s)
|
||||||
|
elif s:self.right = child
|
||||||
|
else:self.left = child
|
||||||
|
class splayTree:
|
||||||
|
def __init__(self,s=[]):
|
||||||
|
s = list(s)
|
||||||
|
self.root = None
|
||||||
|
s = sorted(s,reverse = True)
|
||||||
|
for i in s:
|
||||||
|
self.insert(self.root,i)
|
||||||
|
def insert(self,k):
|
||||||
|
if not self.root :self.root = node(k)
|
||||||
|
else:self._insert(self.root,k)
|
||||||
|
def _insert(self,root,k):
|
||||||
|
if root.val == k :
|
||||||
|
root.freq +=1
|
||||||
|
elif root.val<k:
|
||||||
|
if not root.right:
|
||||||
|
root.right = node(k)
|
||||||
|
root.right.parent = root
|
||||||
|
else:self._insert(root.right,k)
|
||||||
|
else:
|
||||||
|
if not root.left:
|
||||||
|
root.left = node(k)
|
||||||
|
root.left.parent = root
|
||||||
|
else:self._insert(root.left,k)
|
||||||
|
def _zigzagRotate(self,i,j,root,parent,grand):
|
||||||
|
parent.setChild(root.getChild(i),j)
|
||||||
|
root.setChild(parent,i)
|
||||||
|
grand.setChild(root.getChild(j),i)
|
||||||
|
root.setChild(grand,j)
|
||||||
|
if root.parent:root.parent = grand.parent
|
||||||
|
parent.parent = root
|
||||||
|
grand.parent = root
|
||||||
|
def _lineRotate(self,i,root,parent,grand):
|
||||||
|
grand.setChild(parent.getChild(i^1),i)
|
||||||
|
parent.setChild(grand,i^1)
|
||||||
|
parent.setChild(root.getChild(i^1),i)
|
||||||
|
root.setChild(parent,i^1)
|
||||||
|
if root.parent:root.parent = grand.parent
|
||||||
|
parent.parent = root
|
||||||
|
grand.parent = parent
|
||||||
|
def _rotate(self,root):
|
||||||
|
if root == self.root:return
|
||||||
|
if root.parent == self.root:
|
||||||
|
for i in range(2):
|
||||||
|
if root.parent.getChild(i) == root:
|
||||||
|
root.parent.parent = root
|
||||||
|
root.parent.setChild(root.getChild(i^1),i)
|
||||||
|
root.parent = None
|
||||||
|
root.setChild(self.root,i^1)
|
||||||
|
self.root = root
|
||||||
|
else:
|
||||||
|
grand = root.parent.parent
|
||||||
|
parent = root.parent
|
||||||
|
if grand == self.root:
|
||||||
|
self.root = root
|
||||||
|
root.parent = None
|
||||||
|
else:
|
||||||
|
for i in range(2):
|
||||||
|
if grand.parent.getChild(i) == grand:
|
||||||
|
grand.parent.setChild(root,i)
|
||||||
|
for i in range(2):
|
||||||
|
for j in range(2):
|
||||||
|
if i!=j and grand.getChild([i,j]) == root:
|
||||||
|
self._zigzagRotate(i,j,root,parent,grand)
|
||||||
|
elif i==j and grand.getChild([i,i]) == root:
|
||||||
|
self._lineRotate(i,root,parent,grand)
|
||||||
|
self._rotate(root)
|
||||||
|
def _find(self,root,k):
|
||||||
|
if not root:return 0
|
||||||
|
if root.val > k:
|
||||||
|
return self._find(root.left,k)
|
||||||
|
elif root.val<k:
|
||||||
|
return self._find(root.right,k)
|
||||||
|
else:
|
||||||
|
self._rotate(root)
|
||||||
|
return root.freq
|
||||||
|
def _maxmin(self,root,i=0):
|
||||||
|
if not root:return None
|
||||||
|
if root.getChild(i):
|
||||||
|
return self._maxmin(root.getChild(i))
|
||||||
|
return root
|
||||||
|
def Max(self):
|
||||||
|
return self._maxmin(self.root,1)
|
||||||
|
def Min(self):
|
||||||
|
return self._maxmin(self.root,0)
|
||||||
|
def remove(self,k):
|
||||||
|
tmp = self.find(k)
|
||||||
|
if not tmp:raise ValueError
|
||||||
|
else:
|
||||||
|
if self.root.left:
|
||||||
|
r = self.root.right
|
||||||
|
self.root = self.root.left
|
||||||
|
self.root.parent = None
|
||||||
|
Max = self.Max()
|
||||||
|
Max.right= r
|
||||||
|
if r:
|
||||||
|
r.parent = Max
|
||||||
|
else:
|
||||||
|
self.root = self.root.right
|
||||||
|
def find(self,k):
|
||||||
|
return self._find(self.root,k)
|
||||||
|
def levelTraverse(self):
|
||||||
|
q = deque()
|
||||||
|
q.append((self.root,0))
|
||||||
|
rst = []
|
||||||
|
while q:
|
||||||
|
tmp,n= q.popleft()
|
||||||
|
rst.append(tmp)
|
||||||
|
if tmp.left:q.append((tmp.left,n+1))
|
||||||
|
if tmp.right:q.append((tmp.right,n+1))
|
||||||
|
return rst
|
||||||
|
def display(self):
|
||||||
|
data = self.levelTraverse()
|
||||||
|
for i in data:
|
||||||
|
print (i.val,end=' ')
|
||||||
|
print('')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
a = splayTree()
|
||||||
|
a.insert(5)
|
||||||
|
a.insert(1)
|
||||||
|
a.insert(4)
|
||||||
|
a.insert(3)
|
||||||
|
a.insert(2)
|
||||||
|
a.insert(7)
|
||||||
|
a.insert(8)
|
||||||
|
a.insert(2)
|
||||||
|
print('initial:5,1,4,2,7,8,2')
|
||||||
|
a.display()
|
||||||
|
tmp = a.find(2)
|
||||||
|
print("after find(2):%d"%tmp)
|
||||||
|
a.display()
|
||||||
|
print("remove(4)")
|
||||||
|
a.remove(4)
|
||||||
|
a.display()
|
103
codes/dataStructure/stack/stack.cc
Normal file
103
codes/dataStructure/stack/stack.cc
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#include<malloc.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<vector>
|
||||||
|
#define SZ 50
|
||||||
|
using namespace std;
|
||||||
|
template<typename type>
|
||||||
|
class stack
|
||||||
|
{
|
||||||
|
int capacity;
|
||||||
|
type *bottom,*top;
|
||||||
|
public:
|
||||||
|
stack(int n = SZ);
|
||||||
|
stack( stack &);
|
||||||
|
stack(int,type);
|
||||||
|
stack(vector<type> &);
|
||||||
|
type pop();
|
||||||
|
int cp();
|
||||||
|
void push(type);
|
||||||
|
bool empty();
|
||||||
|
type getTop();
|
||||||
|
};
|
||||||
|
template<typename type>
|
||||||
|
stack<type>::stack(int n):capacity(n)
|
||||||
|
{
|
||||||
|
bottom = new type[capacity+1];
|
||||||
|
top = bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename type>
|
||||||
|
stack<type>::stack(int n,type x):capacity(n*2)
|
||||||
|
{
|
||||||
|
bottom = new type[capacity+1];
|
||||||
|
top = bottom;
|
||||||
|
for(int i = 0;i<n;++i)*(++top) = x;
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
stack<type>::stack(vector<type> &vc):capacity (vc.size()*2)
|
||||||
|
{
|
||||||
|
bottom = new type[capacity+1];
|
||||||
|
top = bottom;
|
||||||
|
for(int i = 0;i!=vc.size();++i){
|
||||||
|
push(vc[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
stack<type>::stack(stack &s):capacity(s.capacity)
|
||||||
|
{
|
||||||
|
bottom = new type[capacity+1];
|
||||||
|
top = bottom;
|
||||||
|
for(type *p= s.bottom;p!=s.top;)*(++top) = *(++p);
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
int stack<type>::cp()
|
||||||
|
{
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
bool stack<type>::empty()
|
||||||
|
{
|
||||||
|
return bottom == top;
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
type stack<type>::getTop()
|
||||||
|
{
|
||||||
|
return *top;
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
type stack<type>::pop()
|
||||||
|
{
|
||||||
|
if(bottom == top){
|
||||||
|
printf("the stack is empty now\n");
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
return *(top--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename type>
|
||||||
|
void stack<type>::push(type x)
|
||||||
|
{
|
||||||
|
if(capacity == top-bottom){
|
||||||
|
bottom = (type *)realloc(bottom,sizeof(type)*(2*capacity+1));
|
||||||
|
top = bottom+capacity;
|
||||||
|
}
|
||||||
|
*(++top) = x;
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
stack<char> sc(5,'z'),scc(sc);
|
||||||
|
printf("stack copy\n");
|
||||||
|
while(!scc.empty()){
|
||||||
|
printf("%c\n",scc.pop());
|
||||||
|
}
|
||||||
|
vector<double> vc(50,2.3);
|
||||||
|
stack<double> sd(vc);
|
||||||
|
sd.push(3.4);
|
||||||
|
printf("gettop%lf\n",sd.getTop());
|
||||||
|
printf("vec copy\n");
|
||||||
|
while(!sd.empty()){
|
||||||
|
printf("%lf\n",sd.pop());
|
||||||
|
}
|
||||||
|
printf("empty %d\ncapacity%d",sd.empty(),sd.cp());
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
codes/dataStructure/stack/stack.exe
Normal file
BIN
codes/dataStructure/stack/stack.exe
Normal file
Binary file not shown.
BIN
codes/dataStructure/stack/stack.o
Normal file
BIN
codes/dataStructure/stack/stack.o
Normal file
Binary file not shown.
57
codes/dataStructure/testAllOne.py
Normal file
57
codes/dataStructure/testAllOne.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
from allOoneDS import AllOne
|
||||||
|
from time import time
|
||||||
|
from random import choice,sample,randint
|
||||||
|
|
||||||
|
class hashMap:
|
||||||
|
def __init__(self):
|
||||||
|
self.op = {"inc":self.inc,"dec":self.dec,"getMaxKey":self.getMaxKey,"getMinKey":self.getMinKey}
|
||||||
|
self.mp={'':0}
|
||||||
|
def inc(self,key,n=1):
|
||||||
|
if key in self.mp:self.mp[key]+=n
|
||||||
|
else:self.mp[key]=n
|
||||||
|
def dec(self,key,n=1):
|
||||||
|
if key not in self.mp:return
|
||||||
|
if self.mp[key]<=n:del self.mp[key]
|
||||||
|
else: self.mp[key]-=n
|
||||||
|
def getMinKey(self):
|
||||||
|
return min(list(self.mp.keys()),key=lambda key:self.mp[key])
|
||||||
|
def getMaxKey(self):
|
||||||
|
return max(list(self.mp.keys()),key=lambda key:self.mp[key])
|
||||||
|
|
||||||
|
|
||||||
|
op_origin = ['inc','dec','getMinKey','getMaxKey']#'getMinKey','getMaxKey','getMinKey','getMaxKey','getMinKey','getMaxKey','getMinKey','getMaxKey']
|
||||||
|
ch=list('qwertyuiopasdfghjklzxcvbnm')
|
||||||
|
keys =[ ''.join(sample(ch,i)) for j in range(10) for i in range(1,20,5)]
|
||||||
|
|
||||||
|
def testCase(n=1000):
|
||||||
|
ops=[]
|
||||||
|
data=[]
|
||||||
|
for i in range(n):
|
||||||
|
p = randint(0,len(op_origin)-1)
|
||||||
|
ops.append(op_origin[p])
|
||||||
|
if p<2:
|
||||||
|
data.append([randint(1,5)])
|
||||||
|
else:data.append([])
|
||||||
|
return ops,data
|
||||||
|
|
||||||
|
def test(repeat=1000):
|
||||||
|
t1,t2=0,0
|
||||||
|
for i in range(repeat):
|
||||||
|
allOne = AllOne()
|
||||||
|
hsmp = hashMap()
|
||||||
|
ops,data = testCase()
|
||||||
|
t1-=time()
|
||||||
|
for op,datum in zip(ops,data):
|
||||||
|
allOne.op[op](*datum)
|
||||||
|
t1+=time()
|
||||||
|
|
||||||
|
t2-=time()
|
||||||
|
for op,datum in zip(ops,data):
|
||||||
|
hsmp.op[op](*datum)
|
||||||
|
t2+=time()
|
||||||
|
return t1,t2
|
||||||
|
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
t1,t2= test()
|
||||||
|
print(t1,t2)
|
86
codes/dataStructure/trie.py
Normal file
86
codes/dataStructure/trie.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
class node:
|
||||||
|
def __init__(self,val = None):
|
||||||
|
self.val = val
|
||||||
|
self.isKey = False
|
||||||
|
self.children = {}
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.children[i]
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.children.keys())
|
||||||
|
def __setitem__(self,i,x):
|
||||||
|
self.children[i] = x
|
||||||
|
def __bool__(self):
|
||||||
|
return self.children!={}
|
||||||
|
def __str__(self):
|
||||||
|
return 'val: '+str(self.val)+'\nchildren: '+' '.join(self.children.keys())
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
|
||||||
|
class Trie(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.root=node('')
|
||||||
|
self.dic ={'insert':self.insert,'startsWith':self.startsWith,'search':self.search}
|
||||||
|
|
||||||
|
def insert(self, word):
|
||||||
|
"""
|
||||||
|
Inserts a word into the trie.
|
||||||
|
:type word: str
|
||||||
|
:rtype: void
|
||||||
|
"""
|
||||||
|
if not word:return
|
||||||
|
nd = self.root
|
||||||
|
for i in word:
|
||||||
|
if i in nd:
|
||||||
|
nd = nd[i]
|
||||||
|
else:
|
||||||
|
newNode= node(i)
|
||||||
|
nd[i] = newNode
|
||||||
|
nd = newNode
|
||||||
|
else:nd.isKey = True
|
||||||
|
def search(self, word,matchAll='.'):
|
||||||
|
"""support matchall function eg, 'p.d' matchs 'pad' , 'pid'
|
||||||
|
"""
|
||||||
|
self.matchAll = '.'
|
||||||
|
return self._search(self.root,word)
|
||||||
|
def _search(self,nd,word):
|
||||||
|
for idx,i in enumerate(word):
|
||||||
|
if i==self.matchAll :
|
||||||
|
for j in nd:
|
||||||
|
bl =self._search(nd[j],word[idx+1:])
|
||||||
|
if bl:return True
|
||||||
|
else:return False
|
||||||
|
if i in nd:
|
||||||
|
nd = nd[i]
|
||||||
|
else:return False
|
||||||
|
else:return nd.isKey
|
||||||
|
def startsWith(self, prefix):
|
||||||
|
"""
|
||||||
|
Returns if there is any word in the trie that starts with the given prefix.
|
||||||
|
:type prefix: str
|
||||||
|
:rtype: bool
|
||||||
|
"""
|
||||||
|
nd = self.root
|
||||||
|
for i in prefix:
|
||||||
|
if i in nd:
|
||||||
|
nd= nd[i]
|
||||||
|
else:return False
|
||||||
|
return True
|
||||||
|
def display(self):
|
||||||
|
print('preOrderTraverse data of the Trie')
|
||||||
|
self.preOrder(self.root,'')
|
||||||
|
def preOrder(self,root,s):
|
||||||
|
s=s+root.val
|
||||||
|
if root.isKey:
|
||||||
|
print(s)
|
||||||
|
for i in root:
|
||||||
|
self.preOrder(root[i],s)
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
t = Trie()
|
||||||
|
rsts = [None,None,None,None,None,None,False,True,False,False,False,False,False,True,True,False,True,True,False,False,False,True,True,True]
|
||||||
|
op = ["insert","insert","insert","insert","insert","insert","search","search","search","search","search","search","search","search","search","startsWith","startsWith","startsWith","startsWith","startsWith","startsWith","startsWith","startsWith","startsWith"]
|
||||||
|
data = [["app"],["apple"],["beer"],["add"],["jam"],["rental"],["apps"],["app"],["ad"],["applepie"],["rest"],["jan"],["rent"],["beer"],["jam"],["apps"],["app"],["ad"],["applepie"],["rest"],["jan"],["rent"],["beer"],["jam"]]
|
||||||
|
for i,datum,rst in zip(op,data,rsts):
|
||||||
|
if t.dic[i](datum[0]) != rst:print(i,datum[0],rst)
|
||||||
|
t.display()
|
96
codes/dataStructure/winnerTree.py
Normal file
96
codes/dataStructure/winnerTree.py
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
class winnerTree:
|
||||||
|
'''if i<lowExt p = (i+offset)//2
|
||||||
|
else p = (i+n-1-lowExt)//2
|
||||||
|
offset is a num 2^k-1 just bigger than n
|
||||||
|
p is the index of tree
|
||||||
|
i is the index of players
|
||||||
|
lowExt is the double node num of the lowest layer of the tree
|
||||||
|
'''
|
||||||
|
def __init__(self,players,reverse=False):
|
||||||
|
self.n=len(players)
|
||||||
|
self.tree = [0]*self.n
|
||||||
|
players.insert(0,0)
|
||||||
|
self.players=players
|
||||||
|
self.reverse=reverse
|
||||||
|
self.getNum()
|
||||||
|
self.initTree(1)
|
||||||
|
def getNum(self):
|
||||||
|
i=1
|
||||||
|
while 2*i< self.n:i=i*2
|
||||||
|
if 2*i ==self. n:
|
||||||
|
self.lowExt=0
|
||||||
|
self.s = 2*i-1
|
||||||
|
else:
|
||||||
|
self.lowExt = (self.n-i)*2
|
||||||
|
self.s = i-1
|
||||||
|
self.offset = 2*i-1
|
||||||
|
def treeToArray(self,p):
|
||||||
|
return 2*p-self.offset if p>self.s else 2*p+self.lowExt-self.n+1
|
||||||
|
def arrayToTree(self,i):
|
||||||
|
return (i+self.offset)//2 if i<=self.lowExt else (i-self.lowExt+ self.n-1)//2
|
||||||
|
def win(self,a,b):
|
||||||
|
return a<b if self.reverse else a>b
|
||||||
|
def initTree(self,p):
|
||||||
|
if p>=self.n:
|
||||||
|
delta = p%2 #!!! good job notice delta mark the lchild or rchlid
|
||||||
|
return self.players[self.treeToArray(p//2)+delta]
|
||||||
|
l = self.initTree(2*p)
|
||||||
|
r = self.initTree(2*p+1)
|
||||||
|
self.tree[p] = l if self.win(l,r) else r
|
||||||
|
return self.tree[p]
|
||||||
|
def winner(self):
|
||||||
|
idx = 1
|
||||||
|
while 2*idx<self.n:
|
||||||
|
idx = 2*idx if self.tree[2*idx] == self.tree[idx] else idx*2+1
|
||||||
|
num = self.treeToArray(idx)
|
||||||
|
num = num+1 if self.players[num] !=self.tree[1] else num
|
||||||
|
return self.tree[1],num
|
||||||
|
def getOppo(self,i,x,p):
|
||||||
|
oppo=None
|
||||||
|
if 2*p<self.n:oppo=self.tree[2*p]
|
||||||
|
elif i<=self.lowExt:oppo=self.players[i-1+i%2*2]
|
||||||
|
else:
|
||||||
|
lpl= self.players[2*p+self.lowExt-self.n+1]
|
||||||
|
oppo = lpl if lpl!=x else self.players[2*p+self.lowExt-self.n+2]
|
||||||
|
return oppo
|
||||||
|
def update(self,i,x):
|
||||||
|
''' i is 1-indexed which is the num of player
|
||||||
|
and x is the new val of the player '''
|
||||||
|
self.players[i]=x
|
||||||
|
p = self.arrayToTree(i)
|
||||||
|
oppo =self.getOppo(i,x,p)
|
||||||
|
self.tree[p] = x if self.win(x,oppo) else oppo
|
||||||
|
p=p//2
|
||||||
|
while p:
|
||||||
|
l = self.tree[p*2]
|
||||||
|
r = None
|
||||||
|
if 2*p+1<self.n:r=self.tree[p*2+1] #notice this !!!
|
||||||
|
else:r = self.players[2*p+self.lowExt-self.n+1]
|
||||||
|
self.tree[p] = l if self.win(l,r) else r
|
||||||
|
p=p//2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
s= [4,1,6,7,9,5234,0,2,7,4,123]
|
||||||
|
t = winnerTree(s)
|
||||||
|
print(t.players,t.tree)
|
||||||
|
for i in s:
|
||||||
|
val,idx=t.winner()
|
||||||
|
print(val,idx)
|
||||||
|
t.update(idx,-1)
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
[0, 4, 1, 6, 7, 9, 5234, 0, 2, 7, 4, 123] [0, 5234, 5234, 123, 7, 5234, 7, 123, 4, 7, 5234]
|
||||||
|
5234 6
|
||||||
|
123 11
|
||||||
|
9 5
|
||||||
|
7 4
|
||||||
|
7 9
|
||||||
|
6 3
|
||||||
|
4 1
|
||||||
|
4 10
|
||||||
|
2 8
|
||||||
|
1 2
|
||||||
|
'''
|
29
codes/four/..spec
Normal file
29
codes/four/..spec
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- mode: python -*-
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(['.'],
|
||||||
|
pathex=['/mnt/c/Users/mbinary/gitrepo/algorithm/codes/four'],
|
||||||
|
binaries=[],
|
||||||
|
datas=[],
|
||||||
|
hiddenimports=[],
|
||||||
|
hookspath=[],
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data,
|
||||||
|
cipher=block_cipher)
|
||||||
|
exe = EXE(pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
name='.',
|
||||||
|
debug=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True )
|
BIN
codes/four/__pycache__/handle.cpython-35.pyc
Normal file
BIN
codes/four/__pycache__/handle.cpython-35.pyc
Normal file
Binary file not shown.
BIN
codes/four/__pycache__/handle.cpython-36.pyc
Normal file
BIN
codes/four/__pycache__/handle.cpython-36.pyc
Normal file
Binary file not shown.
BIN
codes/four/build/..spec/base_library.zip
Normal file
BIN
codes/four/build/..spec/base_library.zip
Normal file
Binary file not shown.
BIN
codes/four/build/handle/base_library.zip
Normal file
BIN
codes/four/build/handle/base_library.zip
Normal file
Binary file not shown.
19
codes/four/build/handle/handle.exe.manifest
Normal file
19
codes/four/build/handle/handle.exe.manifest
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<assemblyIdentity name="handle" processorArchitecture="amd64" type="win32" version="1.0.0.0"/>
|
||||||
|
<dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
|
||||||
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||||
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
</assembly>
|
BIN
codes/four/build/handle/localpycos/pyimod01_os_path.pyc
Normal file
BIN
codes/four/build/handle/localpycos/pyimod01_os_path.pyc
Normal file
Binary file not shown.
BIN
codes/four/build/handle/localpycos/pyimod02_archive.pyc
Normal file
BIN
codes/four/build/handle/localpycos/pyimod02_archive.pyc
Normal file
Binary file not shown.
BIN
codes/four/build/handle/localpycos/pyimod03_importers.pyc
Normal file
BIN
codes/four/build/handle/localpycos/pyimod03_importers.pyc
Normal file
Binary file not shown.
BIN
codes/four/build/handle/localpycos/struct.pyo
Normal file
BIN
codes/four/build/handle/localpycos/struct.pyo
Normal file
Binary file not shown.
409
codes/four/build/handle/out00-Analysis.toc
Normal file
409
codes/four/build/handle/out00-Analysis.toc
Normal file
|
@ -0,0 +1,409 @@
|
||||||
|
(['C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\handle.py'],
|
||||||
|
['C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four'],
|
||||||
|
['codecs'],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
False,
|
||||||
|
False,
|
||||||
|
'3.6.2 |Anaconda custom (64-bit)| (default, Jul 20 2017, 12:30:02) [MSC '
|
||||||
|
'v.1900 64 bit (AMD64)]',
|
||||||
|
[('handle',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\handle.py',
|
||||||
|
'PYSOURCE')],
|
||||||
|
[('ntpath', 'd:\\applications\\amacpmda3\\lib\\ntpath.py', 'PYMODULE'),
|
||||||
|
('_strptime', 'd:\\applications\\amacpmda3\\lib\\_strptime.py', 'PYMODULE'),
|
||||||
|
('datetime', 'd:\\applications\\amacpmda3\\lib\\datetime.py', 'PYMODULE'),
|
||||||
|
('stringprep', 'd:\\applications\\amacpmda3\\lib\\stringprep.py', 'PYMODULE'),
|
||||||
|
('stat', 'd:\\applications\\amacpmda3\\lib\\stat.py', 'PYMODULE'),
|
||||||
|
('genericpath',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\genericpath.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('posixpath', 'd:\\applications\\amacpmda3\\lib\\posixpath.py', 'PYMODULE'),
|
||||||
|
('fnmatch', 'd:\\applications\\amacpmda3\\lib\\fnmatch.py', 'PYMODULE'),
|
||||||
|
('_compat_pickle',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_compat_pickle.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('__future__', 'd:\\applications\\amacpmda3\\lib\\__future__.py', 'PYMODULE'),
|
||||||
|
('difflib', 'd:\\applications\\amacpmda3\\lib\\difflib.py', 'PYMODULE'),
|
||||||
|
('ast', 'd:\\applications\\amacpmda3\\lib\\ast.py', 'PYMODULE'),
|
||||||
|
('inspect', 'd:\\applications\\amacpmda3\\lib\\inspect.py', 'PYMODULE'),
|
||||||
|
('cmd', 'd:\\applications\\amacpmda3\\lib\\cmd.py', 'PYMODULE'),
|
||||||
|
('bdb', 'd:\\applications\\amacpmda3\\lib\\bdb.py', 'PYMODULE'),
|
||||||
|
('opcode', 'd:\\applications\\amacpmda3\\lib\\opcode.py', 'PYMODULE'),
|
||||||
|
('dis', 'd:\\applications\\amacpmda3\\lib\\dis.py', 'PYMODULE'),
|
||||||
|
('codeop', 'd:\\applications\\amacpmda3\\lib\\codeop.py', 'PYMODULE'),
|
||||||
|
('code', 'd:\\applications\\amacpmda3\\lib\\code.py', 'PYMODULE'),
|
||||||
|
('glob', 'd:\\applications\\amacpmda3\\lib\\glob.py', 'PYMODULE'),
|
||||||
|
('shlex', 'd:\\applications\\amacpmda3\\lib\\shlex.py', 'PYMODULE'),
|
||||||
|
('importlib._bootstrap',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\_bootstrap.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib._bootstrap_external',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\_bootstrap_external.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib.machinery',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\machinery.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib.util',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\util.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib.abc',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\abc.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pkgutil', 'd:\\applications\\amacpmda3\\lib\\pkgutil.py', 'PYMODULE'),
|
||||||
|
('xml', 'd:\\applications\\amacpmda3\\lib\\xml\\__init__.py', 'PYMODULE'),
|
||||||
|
('xml.sax.expatreader',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\expatreader.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax.saxutils',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\saxutils.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib.request',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\request.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('getpass', 'd:\\applications\\amacpmda3\\lib\\getpass.py', 'PYMODULE'),
|
||||||
|
('nturl2path', 'd:\\applications\\amacpmda3\\lib\\nturl2path.py', 'PYMODULE'),
|
||||||
|
('ftplib', 'd:\\applications\\amacpmda3\\lib\\ftplib.py', 'PYMODULE'),
|
||||||
|
('netrc', 'd:\\applications\\amacpmda3\\lib\\netrc.py', 'PYMODULE'),
|
||||||
|
('http.cookiejar',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\http\\cookiejar.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib.response',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\response.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib.error',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\error.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax.handler',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\handler.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax._exceptions',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\_exceptions.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax.xmlreader',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\xmlreader.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.parsers',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\parsers\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.parsers.expat',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\parsers\\expat.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('plistlib', 'd:\\applications\\amacpmda3\\lib\\plistlib.py', 'PYMODULE'),
|
||||||
|
('platform', 'd:\\applications\\amacpmda3\\lib\\platform.py', 'PYMODULE'),
|
||||||
|
('urllib.parse',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\parse.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('tempfile', 'd:\\applications\\amacpmda3\\lib\\tempfile.py', 'PYMODULE'),
|
||||||
|
('tty', 'd:\\applications\\amacpmda3\\lib\\tty.py', 'PYMODULE'),
|
||||||
|
('pydoc_data',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\pydoc_data\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pydoc_data.topics',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\pydoc_data\\topics.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('html.entities',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\html\\entities.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('html', 'd:\\applications\\amacpmda3\\lib\\html\\__init__.py', 'PYMODULE'),
|
||||||
|
('ipaddress', 'd:\\applications\\amacpmda3\\lib\\ipaddress.py', 'PYMODULE'),
|
||||||
|
('ssl', 'd:\\applications\\amacpmda3\\lib\\ssl.py', 'PYMODULE'),
|
||||||
|
('http.client',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\http\\client.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('mimetypes', 'd:\\applications\\amacpmda3\\lib\\mimetypes.py', 'PYMODULE'),
|
||||||
|
('socketserver',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\socketserver.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('http', 'd:\\applications\\amacpmda3\\lib\\http\\__init__.py', 'PYMODULE'),
|
||||||
|
('http.server',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\http\\server.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('optparse', 'd:\\applications\\amacpmda3\\lib\\optparse.py', 'PYMODULE'),
|
||||||
|
('uu', 'd:\\applications\\amacpmda3\\lib\\uu.py', 'PYMODULE'),
|
||||||
|
('quopri', 'd:\\applications\\amacpmda3\\lib\\quopri.py', 'PYMODULE'),
|
||||||
|
('email.feedparser',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\feedparser.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.parser',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\parser.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email', 'd:\\applications\\amacpmda3\\lib\\email\\__init__.py', 'PYMODULE'),
|
||||||
|
('calendar', 'd:\\applications\\amacpmda3\\lib\\calendar.py', 'PYMODULE'),
|
||||||
|
('email._parseaddr',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_parseaddr.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.utils',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\utils.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.errors',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\errors.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.header',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\header.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email._policybase',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_policybase.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.base64mime',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\base64mime.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.encoders',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\encoders.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.charset',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\charset.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('base64', 'd:\\applications\\amacpmda3\\lib\\base64.py', 'PYMODULE'),
|
||||||
|
('email._encoded_words',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_encoded_words.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('hashlib', 'd:\\applications\\amacpmda3\\lib\\hashlib.py', 'PYMODULE'),
|
||||||
|
('bisect', 'd:\\applications\\amacpmda3\\lib\\bisect.py', 'PYMODULE'),
|
||||||
|
('email.generator',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\generator.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.iterators',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\iterators.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email._header_value_parser',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_header_value_parser.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.headerregistry',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\headerregistry.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.quoprimime',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\quoprimime.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.contentmanager',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\contentmanager.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.policy',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\policy.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.message',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\message.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('bz2', 'd:\\applications\\amacpmda3\\lib\\bz2.py', 'PYMODULE'),
|
||||||
|
('lzma', 'd:\\applications\\amacpmda3\\lib\\lzma.py', 'PYMODULE'),
|
||||||
|
('_compression',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_compression.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('gzip', 'd:\\applications\\amacpmda3\\lib\\gzip.py', 'PYMODULE'),
|
||||||
|
('tarfile', 'd:\\applications\\amacpmda3\\lib\\tarfile.py', 'PYMODULE'),
|
||||||
|
('py_compile', 'd:\\applications\\amacpmda3\\lib\\py_compile.py', 'PYMODULE'),
|
||||||
|
('zipfile', 'd:\\applications\\amacpmda3\\lib\\zipfile.py', 'PYMODULE'),
|
||||||
|
('shutil', 'd:\\applications\\amacpmda3\\lib\\shutil.py', 'PYMODULE'),
|
||||||
|
('socket', 'd:\\applications\\amacpmda3\\lib\\socket.py', 'PYMODULE'),
|
||||||
|
('webbrowser', 'd:\\applications\\amacpmda3\\lib\\webbrowser.py', 'PYMODULE'),
|
||||||
|
('pydoc', 'd:\\applications\\amacpmda3\\lib\\pydoc.py', 'PYMODULE'),
|
||||||
|
('getopt', 'd:\\applications\\amacpmda3\\lib\\getopt.py', 'PYMODULE'),
|
||||||
|
('pdb', 'd:\\applications\\amacpmda3\\lib\\pdb.py', 'PYMODULE'),
|
||||||
|
('unittest.util',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\util.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.result',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\result.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('string', 'd:\\applications\\amacpmda3\\lib\\string.py', 'PYMODULE'),
|
||||||
|
('logging',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\logging\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.case',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\case.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.suite',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\suite.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.loader',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\loader.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.runner',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\runner.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.main',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\main.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.signals',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\signals.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('doctest', 'd:\\applications\\amacpmda3\\lib\\doctest.py', 'PYMODULE'),
|
||||||
|
('pprint', 'd:\\applications\\amacpmda3\\lib\\pprint.py', 'PYMODULE'),
|
||||||
|
('tracemalloc',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\tracemalloc.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('warnings', 'd:\\applications\\amacpmda3\\lib\\warnings.py', 'PYMODULE'),
|
||||||
|
('enum', 'd:\\applications\\amacpmda3\\lib\\enum.py', 'PYMODULE'),
|
||||||
|
('signal', 'd:\\applications\\amacpmda3\\lib\\signal.py', 'PYMODULE'),
|
||||||
|
('contextlib', 'd:\\applications\\amacpmda3\\lib\\contextlib.py', 'PYMODULE'),
|
||||||
|
('_threading_local',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_threading_local.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('threading', 'd:\\applications\\amacpmda3\\lib\\threading.py', 'PYMODULE'),
|
||||||
|
('selectors', 'd:\\applications\\amacpmda3\\lib\\selectors.py', 'PYMODULE'),
|
||||||
|
('_dummy_thread',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_dummy_thread.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('dummy_threading',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\dummy_threading.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('subprocess', 'd:\\applications\\amacpmda3\\lib\\subprocess.py', 'PYMODULE'),
|
||||||
|
('os', 'd:\\applications\\amacpmda3\\lib\\os.py', 'PYMODULE'),
|
||||||
|
('token', 'd:\\applications\\amacpmda3\\lib\\token.py', 'PYMODULE'),
|
||||||
|
('copy', 'd:\\applications\\amacpmda3\\lib\\copy.py', 'PYMODULE'),
|
||||||
|
('textwrap', 'd:\\applications\\amacpmda3\\lib\\textwrap.py', 'PYMODULE'),
|
||||||
|
('struct', 'd:\\applications\\amacpmda3\\lib\\struct.py', 'PYMODULE'),
|
||||||
|
('gettext', 'd:\\applications\\amacpmda3\\lib\\gettext.py', 'PYMODULE'),
|
||||||
|
('argparse', 'd:\\applications\\amacpmda3\\lib\\argparse.py', 'PYMODULE'),
|
||||||
|
('tokenize', 'd:\\applications\\amacpmda3\\lib\\tokenize.py', 'PYMODULE'),
|
||||||
|
('random', 'd:\\applications\\amacpmda3\\lib\\random.py', 'PYMODULE'),
|
||||||
|
('pickle', 'd:\\applications\\amacpmda3\\lib\\pickle.py', 'PYMODULE')],
|
||||||
|
[('api-ms-win-crt-heap-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-heap-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('VCRUNTIME140.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\VCRUNTIME140.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-locale-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-locale-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-runtime-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-runtime-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-math-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-math-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-stdio-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-stdio-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('python36.dll', 'd:\\applications\\amacpmda3\\python36.dll', 'BINARY'),
|
||||||
|
('ucrtbase.dll', 'd:\\applications\\amacpmda3\\ucrtbase.dll', 'BINARY'),
|
||||||
|
('api-ms-win-crt-convert-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-convert-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-string-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-string-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-environment-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-environment-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-filesystem-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-filesystem-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-process-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-process-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-conio-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-conio-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-time-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-time-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-synch-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-synch-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-handle-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-handle-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l2-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l2-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processthreads-l1-1-1.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processthreads-l1-1-1.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processenvironment-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processenvironment-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-rtlsupport-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-rtlsupport-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-debug-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-debug-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-timezone-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-timezone-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-datetime-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-datetime-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-util-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-util-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-errorhandling-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-errorhandling-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-profile-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-profile-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-synch-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-synch-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-libraryloader-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-libraryloader-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-string-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-string-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-localization-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-localization-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-interlocked-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-interlocked-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processthreads-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processthreads-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-heap-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-heap-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-namedpipe-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-namedpipe-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-sysinfo-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-sysinfo-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-console-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-console-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-memory-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-memory-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('_ssl', 'd:\\applications\\amacpmda3\\DLLs\\_ssl.pyd', 'EXTENSION'),
|
||||||
|
('unicodedata',
|
||||||
|
'd:\\applications\\amacpmda3\\DLLs\\unicodedata.pyd',
|
||||||
|
'EXTENSION'),
|
||||||
|
('pyexpat', 'd:\\applications\\amacpmda3\\DLLs\\pyexpat.pyd', 'EXTENSION'),
|
||||||
|
('_hashlib', 'd:\\applications\\amacpmda3\\DLLs\\_hashlib.pyd', 'EXTENSION'),
|
||||||
|
('_bz2', 'd:\\applications\\amacpmda3\\DLLs\\_bz2.pyd', 'EXTENSION'),
|
||||||
|
('_lzma', 'd:\\applications\\amacpmda3\\DLLs\\_lzma.pyd', 'EXTENSION'),
|
||||||
|
('_socket', 'd:\\applications\\amacpmda3\\DLLs\\_socket.pyd', 'EXTENSION'),
|
||||||
|
('select', 'd:\\applications\\amacpmda3\\DLLs\\select.pyd', 'EXTENSION'),
|
||||||
|
('api-ms-win-crt-utility-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-utility-l1-1-0.dll',
|
||||||
|
'BINARY')],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
[('base_library.zip',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\base_library.zip',
|
||||||
|
'DATA')],
|
||||||
|
[])
|
173
codes/four/build/handle/out00-EXE.toc
Normal file
173
codes/four/build/handle/out00-EXE.toc
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
('C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\dist\\handle.exe',
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
False,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
False,
|
||||||
|
False,
|
||||||
|
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"><assemblyIdentity name="handle" processorArchitecture="amd64" type="win32" version="1.0.0.0"/><dependency><dependentAssembly><assemblyIdentity language="*" name="Microsoft.Windows.Common-Controls" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" type="win32" version="6.0.0.0"/><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"/></dependentAssembly></dependency><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/></application></compatibility></assembly>',
|
||||||
|
True,
|
||||||
|
'handle.pkg',
|
||||||
|
[('out00-PYZ.pyz',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\out00-PYZ.pyz',
|
||||||
|
'PYZ'),
|
||||||
|
('struct', 'd:\\applications\\amacpmda3\\lib\\struct.pyo', 'PYMODULE'),
|
||||||
|
('pyimod01_os_path',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod01_os_path.pyc',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pyimod02_archive',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod02_archive.pyc',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pyimod03_importers',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod03_importers.pyc',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pyiboot01_bootstrap',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyiboot01_bootstrap.py',
|
||||||
|
'PYSOURCE'),
|
||||||
|
('handle',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\handle.py',
|
||||||
|
'PYSOURCE'),
|
||||||
|
('api-ms-win-crt-heap-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-heap-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('VCRUNTIME140.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\VCRUNTIME140.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-locale-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-locale-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-runtime-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-runtime-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-math-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-math-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-stdio-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-stdio-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('python36.dll', 'd:\\applications\\amacpmda3\\python36.dll', 'BINARY'),
|
||||||
|
('ucrtbase.dll', 'd:\\applications\\amacpmda3\\ucrtbase.dll', 'BINARY'),
|
||||||
|
('api-ms-win-crt-convert-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-convert-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-string-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-string-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-environment-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-environment-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-filesystem-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-filesystem-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-process-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-process-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-conio-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-conio-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-time-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-time-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-synch-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-synch-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-handle-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-handle-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l2-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l2-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processthreads-l1-1-1.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processthreads-l1-1-1.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processenvironment-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processenvironment-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-rtlsupport-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-rtlsupport-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-debug-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-debug-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-timezone-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-timezone-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-datetime-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-datetime-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-util-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-util-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-errorhandling-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-errorhandling-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-profile-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-profile-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-synch-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-synch-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-libraryloader-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-libraryloader-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-string-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-string-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-localization-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-localization-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-interlocked-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-interlocked-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processthreads-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processthreads-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-heap-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-heap-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-namedpipe-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-namedpipe-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-sysinfo-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-sysinfo-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-console-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-console-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-memory-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-memory-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('_ssl', 'd:\\applications\\amacpmda3\\DLLs\\_ssl.pyd', 'EXTENSION'),
|
||||||
|
('unicodedata',
|
||||||
|
'd:\\applications\\amacpmda3\\DLLs\\unicodedata.pyd',
|
||||||
|
'EXTENSION'),
|
||||||
|
('pyexpat', 'd:\\applications\\amacpmda3\\DLLs\\pyexpat.pyd', 'EXTENSION'),
|
||||||
|
('_hashlib', 'd:\\applications\\amacpmda3\\DLLs\\_hashlib.pyd', 'EXTENSION'),
|
||||||
|
('_bz2', 'd:\\applications\\amacpmda3\\DLLs\\_bz2.pyd', 'EXTENSION'),
|
||||||
|
('_lzma', 'd:\\applications\\amacpmda3\\DLLs\\_lzma.pyd', 'EXTENSION'),
|
||||||
|
('_socket', 'd:\\applications\\amacpmda3\\DLLs\\_socket.pyd', 'EXTENSION'),
|
||||||
|
('select', 'd:\\applications\\amacpmda3\\DLLs\\select.pyd', 'EXTENSION'),
|
||||||
|
('api-ms-win-crt-utility-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-utility-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('base_library.zip',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\base_library.zip',
|
||||||
|
'DATA'),
|
||||||
|
('handle.exe.manifest',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\handle.exe.manifest',
|
||||||
|
'BINARY'),
|
||||||
|
('pyi-windows-manifest-filename handle.exe.manifest', '', 'OPTION')],
|
||||||
|
[],
|
||||||
|
False,
|
||||||
|
False,
|
||||||
|
1530888531,
|
||||||
|
[('run.exe',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\bootloader\\Windows-64bit\\run.exe',
|
||||||
|
'EXECUTABLE')])
|
BIN
codes/four/build/handle/out00-PKG.pkg
Normal file
BIN
codes/four/build/handle/out00-PKG.pkg
Normal file
Binary file not shown.
166
codes/four/build/handle/out00-PKG.toc
Normal file
166
codes/four/build/handle/out00-PKG.toc
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
('C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\out00-PKG.pkg',
|
||||||
|
{'BINARY': 1,
|
||||||
|
'DATA': 1,
|
||||||
|
'EXECUTABLE': 1,
|
||||||
|
'EXTENSION': 1,
|
||||||
|
'PYMODULE': 1,
|
||||||
|
'PYSOURCE': 1,
|
||||||
|
'PYZ': 0},
|
||||||
|
[('out00-PYZ.pyz',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\out00-PYZ.pyz',
|
||||||
|
'PYZ'),
|
||||||
|
('struct', 'd:\\applications\\amacpmda3\\lib\\struct.pyo', 'PYMODULE'),
|
||||||
|
('pyimod01_os_path',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod01_os_path.pyc',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pyimod02_archive',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod02_archive.pyc',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pyimod03_importers',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod03_importers.pyc',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pyiboot01_bootstrap',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\site-packages\\PyInstaller\\loader\\pyiboot01_bootstrap.py',
|
||||||
|
'PYSOURCE'),
|
||||||
|
('handle',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\handle.py',
|
||||||
|
'PYSOURCE'),
|
||||||
|
('api-ms-win-crt-heap-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-heap-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('VCRUNTIME140.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\VCRUNTIME140.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-locale-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-locale-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-runtime-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-runtime-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-math-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-math-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-stdio-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-stdio-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('python36.dll', 'd:\\applications\\amacpmda3\\python36.dll', 'BINARY'),
|
||||||
|
('ucrtbase.dll', 'd:\\applications\\amacpmda3\\ucrtbase.dll', 'BINARY'),
|
||||||
|
('api-ms-win-crt-convert-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-convert-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-string-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-string-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-environment-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-environment-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-filesystem-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-filesystem-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-process-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-process-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-conio-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-conio-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-crt-time-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-time-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-synch-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-synch-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-handle-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-handle-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l2-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l2-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processthreads-l1-1-1.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processthreads-l1-1-1.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processenvironment-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processenvironment-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-file-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-file-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-rtlsupport-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-rtlsupport-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-debug-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-debug-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-timezone-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-timezone-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-datetime-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-datetime-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-util-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-util-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-errorhandling-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-errorhandling-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-profile-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-profile-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-synch-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-synch-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-libraryloader-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-libraryloader-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-string-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-string-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-localization-l1-2-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-localization-l1-2-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-interlocked-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-interlocked-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-processthreads-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-processthreads-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-heap-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-heap-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-namedpipe-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-namedpipe-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-sysinfo-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-sysinfo-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-console-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-console-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('api-ms-win-core-memory-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-core-memory-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('_ssl', 'd:\\applications\\amacpmda3\\DLLs\\_ssl.pyd', 'EXTENSION'),
|
||||||
|
('unicodedata',
|
||||||
|
'd:\\applications\\amacpmda3\\DLLs\\unicodedata.pyd',
|
||||||
|
'EXTENSION'),
|
||||||
|
('pyexpat', 'd:\\applications\\amacpmda3\\DLLs\\pyexpat.pyd', 'EXTENSION'),
|
||||||
|
('_hashlib', 'd:\\applications\\amacpmda3\\DLLs\\_hashlib.pyd', 'EXTENSION'),
|
||||||
|
('_bz2', 'd:\\applications\\amacpmda3\\DLLs\\_bz2.pyd', 'EXTENSION'),
|
||||||
|
('_lzma', 'd:\\applications\\amacpmda3\\DLLs\\_lzma.pyd', 'EXTENSION'),
|
||||||
|
('_socket', 'd:\\applications\\amacpmda3\\DLLs\\_socket.pyd', 'EXTENSION'),
|
||||||
|
('select', 'd:\\applications\\amacpmda3\\DLLs\\select.pyd', 'EXTENSION'),
|
||||||
|
('api-ms-win-crt-utility-l1-1-0.dll',
|
||||||
|
'd:\\applications\\amacpmda3\\api-ms-win-crt-utility-l1-1-0.dll',
|
||||||
|
'BINARY'),
|
||||||
|
('base_library.zip',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\base_library.zip',
|
||||||
|
'DATA'),
|
||||||
|
('handle.exe.manifest',
|
||||||
|
'C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\handle.exe.manifest',
|
||||||
|
'BINARY'),
|
||||||
|
('pyi-windows-manifest-filename handle.exe.manifest', '', 'OPTION')],
|
||||||
|
False,
|
||||||
|
False,
|
||||||
|
False)
|
BIN
codes/four/build/handle/out00-PYZ.pyz
Normal file
BIN
codes/four/build/handle/out00-PYZ.pyz
Normal file
Binary file not shown.
261
codes/four/build/handle/out00-PYZ.toc
Normal file
261
codes/four/build/handle/out00-PYZ.toc
Normal file
|
@ -0,0 +1,261 @@
|
||||||
|
('C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four\\build\\handle\\out00-PYZ.pyz',
|
||||||
|
[('ntpath', 'd:\\applications\\amacpmda3\\lib\\ntpath.py', 'PYMODULE'),
|
||||||
|
('_strptime', 'd:\\applications\\amacpmda3\\lib\\_strptime.py', 'PYMODULE'),
|
||||||
|
('datetime', 'd:\\applications\\amacpmda3\\lib\\datetime.py', 'PYMODULE'),
|
||||||
|
('stringprep', 'd:\\applications\\amacpmda3\\lib\\stringprep.py', 'PYMODULE'),
|
||||||
|
('stat', 'd:\\applications\\amacpmda3\\lib\\stat.py', 'PYMODULE'),
|
||||||
|
('genericpath',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\genericpath.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('posixpath', 'd:\\applications\\amacpmda3\\lib\\posixpath.py', 'PYMODULE'),
|
||||||
|
('fnmatch', 'd:\\applications\\amacpmda3\\lib\\fnmatch.py', 'PYMODULE'),
|
||||||
|
('_compat_pickle',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_compat_pickle.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('__future__', 'd:\\applications\\amacpmda3\\lib\\__future__.py', 'PYMODULE'),
|
||||||
|
('difflib', 'd:\\applications\\amacpmda3\\lib\\difflib.py', 'PYMODULE'),
|
||||||
|
('ast', 'd:\\applications\\amacpmda3\\lib\\ast.py', 'PYMODULE'),
|
||||||
|
('inspect', 'd:\\applications\\amacpmda3\\lib\\inspect.py', 'PYMODULE'),
|
||||||
|
('cmd', 'd:\\applications\\amacpmda3\\lib\\cmd.py', 'PYMODULE'),
|
||||||
|
('bdb', 'd:\\applications\\amacpmda3\\lib\\bdb.py', 'PYMODULE'),
|
||||||
|
('opcode', 'd:\\applications\\amacpmda3\\lib\\opcode.py', 'PYMODULE'),
|
||||||
|
('dis', 'd:\\applications\\amacpmda3\\lib\\dis.py', 'PYMODULE'),
|
||||||
|
('codeop', 'd:\\applications\\amacpmda3\\lib\\codeop.py', 'PYMODULE'),
|
||||||
|
('code', 'd:\\applications\\amacpmda3\\lib\\code.py', 'PYMODULE'),
|
||||||
|
('glob', 'd:\\applications\\amacpmda3\\lib\\glob.py', 'PYMODULE'),
|
||||||
|
('shlex', 'd:\\applications\\amacpmda3\\lib\\shlex.py', 'PYMODULE'),
|
||||||
|
('importlib._bootstrap',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\_bootstrap.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib._bootstrap_external',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\_bootstrap_external.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib.machinery',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\machinery.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib.util',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\util.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib.abc',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\abc.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('importlib',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\importlib\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pkgutil', 'd:\\applications\\amacpmda3\\lib\\pkgutil.py', 'PYMODULE'),
|
||||||
|
('xml', 'd:\\applications\\amacpmda3\\lib\\xml\\__init__.py', 'PYMODULE'),
|
||||||
|
('xml.sax.expatreader',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\expatreader.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax.saxutils',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\saxutils.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib.request',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\request.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('getpass', 'd:\\applications\\amacpmda3\\lib\\getpass.py', 'PYMODULE'),
|
||||||
|
('nturl2path', 'd:\\applications\\amacpmda3\\lib\\nturl2path.py', 'PYMODULE'),
|
||||||
|
('ftplib', 'd:\\applications\\amacpmda3\\lib\\ftplib.py', 'PYMODULE'),
|
||||||
|
('netrc', 'd:\\applications\\amacpmda3\\lib\\netrc.py', 'PYMODULE'),
|
||||||
|
('http.cookiejar',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\http\\cookiejar.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib.response',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\response.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib.error',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\error.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax.handler',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\handler.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax._exceptions',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\_exceptions.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.sax.xmlreader',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\sax\\xmlreader.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.parsers',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\parsers\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('xml.parsers.expat',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\xml\\parsers\\expat.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('plistlib', 'd:\\applications\\amacpmda3\\lib\\plistlib.py', 'PYMODULE'),
|
||||||
|
('platform', 'd:\\applications\\amacpmda3\\lib\\platform.py', 'PYMODULE'),
|
||||||
|
('urllib.parse',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\parse.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('tempfile', 'd:\\applications\\amacpmda3\\lib\\tempfile.py', 'PYMODULE'),
|
||||||
|
('tty', 'd:\\applications\\amacpmda3\\lib\\tty.py', 'PYMODULE'),
|
||||||
|
('pydoc_data',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\pydoc_data\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('pydoc_data.topics',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\pydoc_data\\topics.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('html.entities',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\html\\entities.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('html', 'd:\\applications\\amacpmda3\\lib\\html\\__init__.py', 'PYMODULE'),
|
||||||
|
('ipaddress', 'd:\\applications\\amacpmda3\\lib\\ipaddress.py', 'PYMODULE'),
|
||||||
|
('ssl', 'd:\\applications\\amacpmda3\\lib\\ssl.py', 'PYMODULE'),
|
||||||
|
('http.client',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\http\\client.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('mimetypes', 'd:\\applications\\amacpmda3\\lib\\mimetypes.py', 'PYMODULE'),
|
||||||
|
('socketserver',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\socketserver.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('http', 'd:\\applications\\amacpmda3\\lib\\http\\__init__.py', 'PYMODULE'),
|
||||||
|
('http.server',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\http\\server.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('optparse', 'd:\\applications\\amacpmda3\\lib\\optparse.py', 'PYMODULE'),
|
||||||
|
('uu', 'd:\\applications\\amacpmda3\\lib\\uu.py', 'PYMODULE'),
|
||||||
|
('quopri', 'd:\\applications\\amacpmda3\\lib\\quopri.py', 'PYMODULE'),
|
||||||
|
('email.feedparser',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\feedparser.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.parser',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\parser.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email', 'd:\\applications\\amacpmda3\\lib\\email\\__init__.py', 'PYMODULE'),
|
||||||
|
('calendar', 'd:\\applications\\amacpmda3\\lib\\calendar.py', 'PYMODULE'),
|
||||||
|
('email._parseaddr',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_parseaddr.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.utils',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\utils.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.errors',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\errors.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.header',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\header.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email._policybase',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_policybase.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.base64mime',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\base64mime.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.encoders',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\encoders.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.charset',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\charset.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('base64', 'd:\\applications\\amacpmda3\\lib\\base64.py', 'PYMODULE'),
|
||||||
|
('email._encoded_words',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_encoded_words.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('hashlib', 'd:\\applications\\amacpmda3\\lib\\hashlib.py', 'PYMODULE'),
|
||||||
|
('bisect', 'd:\\applications\\amacpmda3\\lib\\bisect.py', 'PYMODULE'),
|
||||||
|
('email.generator',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\generator.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.iterators',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\iterators.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('urllib',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\urllib\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email._header_value_parser',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\_header_value_parser.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.headerregistry',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\headerregistry.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.quoprimime',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\quoprimime.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.contentmanager',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\contentmanager.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.policy',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\policy.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('email.message',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\email\\message.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('bz2', 'd:\\applications\\amacpmda3\\lib\\bz2.py', 'PYMODULE'),
|
||||||
|
('lzma', 'd:\\applications\\amacpmda3\\lib\\lzma.py', 'PYMODULE'),
|
||||||
|
('_compression',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_compression.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('gzip', 'd:\\applications\\amacpmda3\\lib\\gzip.py', 'PYMODULE'),
|
||||||
|
('tarfile', 'd:\\applications\\amacpmda3\\lib\\tarfile.py', 'PYMODULE'),
|
||||||
|
('py_compile', 'd:\\applications\\amacpmda3\\lib\\py_compile.py', 'PYMODULE'),
|
||||||
|
('zipfile', 'd:\\applications\\amacpmda3\\lib\\zipfile.py', 'PYMODULE'),
|
||||||
|
('shutil', 'd:\\applications\\amacpmda3\\lib\\shutil.py', 'PYMODULE'),
|
||||||
|
('socket', 'd:\\applications\\amacpmda3\\lib\\socket.py', 'PYMODULE'),
|
||||||
|
('webbrowser', 'd:\\applications\\amacpmda3\\lib\\webbrowser.py', 'PYMODULE'),
|
||||||
|
('pydoc', 'd:\\applications\\amacpmda3\\lib\\pydoc.py', 'PYMODULE'),
|
||||||
|
('getopt', 'd:\\applications\\amacpmda3\\lib\\getopt.py', 'PYMODULE'),
|
||||||
|
('pdb', 'd:\\applications\\amacpmda3\\lib\\pdb.py', 'PYMODULE'),
|
||||||
|
('unittest.util',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\util.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.result',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\result.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('string', 'd:\\applications\\amacpmda3\\lib\\string.py', 'PYMODULE'),
|
||||||
|
('logging',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\logging\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.case',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\case.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.suite',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\suite.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.loader',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\loader.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.runner',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\runner.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.main',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\main.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest.signals',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\signals.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('unittest',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\unittest\\__init__.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('doctest', 'd:\\applications\\amacpmda3\\lib\\doctest.py', 'PYMODULE'),
|
||||||
|
('pprint', 'd:\\applications\\amacpmda3\\lib\\pprint.py', 'PYMODULE'),
|
||||||
|
('tracemalloc',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\tracemalloc.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('warnings', 'd:\\applications\\amacpmda3\\lib\\warnings.py', 'PYMODULE'),
|
||||||
|
('enum', 'd:\\applications\\amacpmda3\\lib\\enum.py', 'PYMODULE'),
|
||||||
|
('signal', 'd:\\applications\\amacpmda3\\lib\\signal.py', 'PYMODULE'),
|
||||||
|
('contextlib', 'd:\\applications\\amacpmda3\\lib\\contextlib.py', 'PYMODULE'),
|
||||||
|
('_threading_local',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_threading_local.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('threading', 'd:\\applications\\amacpmda3\\lib\\threading.py', 'PYMODULE'),
|
||||||
|
('selectors', 'd:\\applications\\amacpmda3\\lib\\selectors.py', 'PYMODULE'),
|
||||||
|
('_dummy_thread',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\_dummy_thread.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('dummy_threading',
|
||||||
|
'd:\\applications\\amacpmda3\\lib\\dummy_threading.py',
|
||||||
|
'PYMODULE'),
|
||||||
|
('subprocess', 'd:\\applications\\amacpmda3\\lib\\subprocess.py', 'PYMODULE'),
|
||||||
|
('os', 'd:\\applications\\amacpmda3\\lib\\os.py', 'PYMODULE'),
|
||||||
|
('token', 'd:\\applications\\amacpmda3\\lib\\token.py', 'PYMODULE'),
|
||||||
|
('copy', 'd:\\applications\\amacpmda3\\lib\\copy.py', 'PYMODULE'),
|
||||||
|
('textwrap', 'd:\\applications\\amacpmda3\\lib\\textwrap.py', 'PYMODULE'),
|
||||||
|
('struct', 'd:\\applications\\amacpmda3\\lib\\struct.py', 'PYMODULE'),
|
||||||
|
('gettext', 'd:\\applications\\amacpmda3\\lib\\gettext.py', 'PYMODULE'),
|
||||||
|
('argparse', 'd:\\applications\\amacpmda3\\lib\\argparse.py', 'PYMODULE'),
|
||||||
|
('tokenize', 'd:\\applications\\amacpmda3\\lib\\tokenize.py', 'PYMODULE'),
|
||||||
|
('random', 'd:\\applications\\amacpmda3\\lib\\random.py', 'PYMODULE'),
|
||||||
|
('pickle', 'd:\\applications\\amacpmda3\\lib\\pickle.py', 'PYMODULE')])
|
17
codes/four/build/handle/warnhandle.txt
Normal file
17
codes/four/build/handle/warnhandle.txt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
missing module named resource - imported by posix, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named posix - imported by os, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named _posixsubprocess - imported by subprocess, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named 'org.python' - imported by pickle, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py, xml.sax
|
||||||
|
missing module named readline - imported by cmd, code, pdb, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
excluded module named _frozen_importlib - imported by importlib, importlib.abc, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named _winreg - imported by platform, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named _scproxy - imported by urllib.request
|
||||||
|
missing module named java - imported by platform, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named 'java.lang' - imported by platform, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py, xml.sax._exceptions
|
||||||
|
missing module named vms_lib - imported by platform, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named termios - imported by tty, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py, getpass
|
||||||
|
missing module named grp - imported by shutil, tarfile, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py, netrc, getpass
|
||||||
|
missing module named _dummy_threading - imported by dummy_threading, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
||||||
|
missing module named org - imported by copy, C:\Users\mbinary\gitrepo\algorithm\codes\four\handle.py
|
8299
codes/four/build/handle/xref-handle.html
Normal file
8299
codes/four/build/handle/xref-handle.html
Normal file
File diff suppressed because it is too large
Load Diff
BIN
codes/four/dist/four.pk
vendored
Normal file
BIN
codes/four/dist/four.pk
vendored
Normal file
Binary file not shown.
BIN
codes/four/dist/handle
vendored
Normal file
BIN
codes/four/dist/handle
vendored
Normal file
Binary file not shown.
BIN
codes/four/dist/handle.exe
vendored
Normal file
BIN
codes/four/dist/handle.exe
vendored
Normal file
Binary file not shown.
BIN
codes/four/four.pk
Normal file
BIN
codes/four/four.pk
Normal file
Binary file not shown.
89
codes/four/handle.py
Normal file
89
codes/four/handle.py
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
from pickle import load,dump
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
def next(dic,s,li):
|
||||||
|
if s[-1] not in dic:
|
||||||
|
if len(li)>10:print(li)
|
||||||
|
return
|
||||||
|
for i in dic[s[-1]]:
|
||||||
|
if i in li: continue
|
||||||
|
next(dic,i,li+[i])
|
||||||
|
def gen(dic):
|
||||||
|
for i in dic:
|
||||||
|
for j in dic[i]:
|
||||||
|
next(dic,j,[j])
|
||||||
|
|
||||||
|
class node:
|
||||||
|
def __init__(self,val):
|
||||||
|
self.val = val
|
||||||
|
self.chd={}
|
||||||
|
self.prt={}
|
||||||
|
def to(self,nd):
|
||||||
|
if nd.val not in self.chd:
|
||||||
|
self.chd[nd.val] = nd
|
||||||
|
nd.prt[self.val] = self
|
||||||
|
def __getitem__(self,i):
|
||||||
|
return self.val[i]
|
||||||
|
def __str__(self):
|
||||||
|
return '{}->{}'.format(self.val,list(self.chd.keys()))
|
||||||
|
def __repr__(self):
|
||||||
|
return 'node({})'.format(self.val)
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.chd)
|
||||||
|
class graph:
|
||||||
|
def __init__(self):
|
||||||
|
self.data = {}
|
||||||
|
def addNode(self,s):
|
||||||
|
if s not in self.data:
|
||||||
|
nd = node(s)
|
||||||
|
for i,j in self.data.items():
|
||||||
|
if i[-1]==nd[0]: j.to(nd)
|
||||||
|
if i[0]== nd[-1]: nd.to(j)
|
||||||
|
self.data[s] = nd
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
print()
|
||||||
|
def __getitem(self,i):
|
||||||
|
return self.data[i]
|
||||||
|
def clean(dic):
|
||||||
|
g = graph()
|
||||||
|
for i in dic:
|
||||||
|
for j in dic[i]:
|
||||||
|
g.addNode(j)
|
||||||
|
|
||||||
|
dic = {}
|
||||||
|
for i,j in g.data.items():
|
||||||
|
if j.chd=={} and j.prt=={}: continue
|
||||||
|
if i[0] in dic: dic[i[0]].append(i)
|
||||||
|
else:dic[i[0]] = [i]
|
||||||
|
|
||||||
|
with open('four.pk','wb') as f:
|
||||||
|
dump(dic,f)
|
||||||
|
def play():
|
||||||
|
def once(last):
|
||||||
|
word = last[-1]
|
||||||
|
if word[-1] not in dic:
|
||||||
|
if len(last)>1:
|
||||||
|
print('{}-> '.format(last))
|
||||||
|
print('-'*5+'end'+'-'*5)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print('{}-> '.format(last))
|
||||||
|
lst = dic[word[-1]]
|
||||||
|
for i,j in enumerate(lst):
|
||||||
|
print('{}. {}'.format(i,j))
|
||||||
|
print('q. quit')
|
||||||
|
choose = input('>>> ')
|
||||||
|
if choose == 'q':return
|
||||||
|
once(last+[lst[int(choose)%len(lst)]])
|
||||||
|
|
||||||
|
lst = dic[li[randint(0,n-1)]]
|
||||||
|
word = lst[randint(0,len(lst)-1)]
|
||||||
|
once([word])
|
||||||
|
if __name__ =='__main__':
|
||||||
|
dic=None
|
||||||
|
with open('four.pk','rb') as f:
|
||||||
|
dic = load(f)
|
||||||
|
li = list(dic.keys())
|
||||||
|
n = len(li)
|
||||||
|
while 1:play()
|
29
codes/four/handle.spec
Normal file
29
codes/four/handle.spec
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- mode: python -*-
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(['handle.py'],
|
||||||
|
pathex=['C:\\Users\\mbinary\\gitrepo\\algorithm\\codes\\four'],
|
||||||
|
binaries=[],
|
||||||
|
datas=[],
|
||||||
|
hiddenimports=[],
|
||||||
|
hookspath=[],
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data,
|
||||||
|
cipher=block_cipher)
|
||||||
|
exe = EXE(pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
name='handle',
|
||||||
|
debug=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True )
|
103
codes/hashTable.py
Normal file
103
codes/hashTable.py
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
class item:
|
||||||
|
def __init__(self,key,val,nextItem=None):
|
||||||
|
self.key = key
|
||||||
|
self.val = val
|
||||||
|
self.next = nextItem
|
||||||
|
def to(self,it):
|
||||||
|
self.next = it
|
||||||
|
def __eq__(self,it):
|
||||||
|
'''using keyword <in> '''
|
||||||
|
return self.key == it.key
|
||||||
|
def __bool__(self):
|
||||||
|
return self.key is not None
|
||||||
|
def __str__(self):
|
||||||
|
li = []
|
||||||
|
nd = self
|
||||||
|
while nd:
|
||||||
|
li.append(f'({nd.key}:{nd.val})')
|
||||||
|
nd = nd.next
|
||||||
|
return ' -> '.join(li)
|
||||||
|
def __repr__(self):
|
||||||
|
return f'item({self.key},{self.val})'
|
||||||
|
class hashTable:
|
||||||
|
def __init__(self,size=100):
|
||||||
|
self.size = size
|
||||||
|
self.slots=[item(None,None) for i in range(self.size)]
|
||||||
|
def __setitem__(self,key,val):
|
||||||
|
nd = self.slots[self.myhash(key)]
|
||||||
|
while nd.next:
|
||||||
|
if nd.key ==key:
|
||||||
|
if nd.val!=val: nd.val=val
|
||||||
|
return
|
||||||
|
nd = nd.next
|
||||||
|
nd.next = item(key,val)
|
||||||
|
|
||||||
|
def myhash(self,key):
|
||||||
|
if isinstance(key,str):
|
||||||
|
key = sum(ord(i) for i in key)
|
||||||
|
if not isinstance(key,int):
|
||||||
|
key = hash(key)
|
||||||
|
return key % self.size
|
||||||
|
def __iter__(self):
|
||||||
|
'''when using keyword <in>, such as ' if key in dic',
|
||||||
|
the dic's __iter__ method will be called,(if hasn't, calls __getitem__
|
||||||
|
then ~iterate~ dic's keys to compare whether one equls to the key
|
||||||
|
'''
|
||||||
|
for nd in self.slots:
|
||||||
|
nd = nd.next
|
||||||
|
while nd :
|
||||||
|
yield nd.key
|
||||||
|
nd = nd.next
|
||||||
|
def __getitem__(self,key):
|
||||||
|
nd =self.slots[ self.myhash(key)].next
|
||||||
|
while nd:
|
||||||
|
if nd.key==key:
|
||||||
|
return nd.val
|
||||||
|
nd = nd.next
|
||||||
|
raise Exception(f'[KeyError]: {self.__class__.__name__} has no key {key}')
|
||||||
|
|
||||||
|
def __delitem__(self,key):
|
||||||
|
'''note that None item and item(None,None) differ with each other,
|
||||||
|
which means you should take care of them and correctly cop with None item
|
||||||
|
especially when deleting items
|
||||||
|
'''
|
||||||
|
n = self.myhash(key)
|
||||||
|
nd = self.slots[n].next
|
||||||
|
if nd.key == key:
|
||||||
|
if nd.next is None:
|
||||||
|
self.slots[n] = item(None,None) # be careful
|
||||||
|
else:self.slots[n] = nd.next
|
||||||
|
return
|
||||||
|
while nd:
|
||||||
|
if nd.next is None: break # necessary
|
||||||
|
if nd.next.key ==key:
|
||||||
|
nd.next = nd.next.next
|
||||||
|
nd = nd.next
|
||||||
|
def __str__(self):
|
||||||
|
li = ['\n\n'+'-'*5+'hashTable'+'-'*5]
|
||||||
|
for i,nd in enumerate(self.slots):
|
||||||
|
li.append(f'{i}: '+str(nd.next))
|
||||||
|
return '\n'.join(li)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
from random import randint
|
||||||
|
dic = hashTable(16)
|
||||||
|
n = 100
|
||||||
|
li = [1,2,5,40,324,123,6,22,18,34,50]
|
||||||
|
print(f'build hashTable using {li}')
|
||||||
|
for i in li:
|
||||||
|
dic[i] = '$'+str(i)
|
||||||
|
print(dic)
|
||||||
|
for i in [1,34,45,123]:
|
||||||
|
if i in dic:
|
||||||
|
print(f'{i} in dic, deleting it')
|
||||||
|
del dic[i]
|
||||||
|
else:
|
||||||
|
print(f'{i} not in dic, ignore it')
|
||||||
|
print(dic)
|
||||||
|
print(f'dic[2] is {dic[2]}')
|
||||||
|
try:
|
||||||
|
dic[-1]
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
26
codes/manacher.py
Normal file
26
codes/manacher.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
class Solution:
|
||||||
|
def longestPalindrome(self, s):
|
||||||
|
"""
|
||||||
|
:type s: str
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
n = len(s)
|
||||||
|
s2='$#'+'#'.join(s)+'#@'
|
||||||
|
ct =[0]*(2*n+4)
|
||||||
|
mid=1
|
||||||
|
for cur in range(1,2*n+2):
|
||||||
|
if cur<mid+ct[mid]:
|
||||||
|
ct[cur] = min(ct[2*mid-cur],mid+ct[mid]-cur)
|
||||||
|
else:
|
||||||
|
ct[cur]=1
|
||||||
|
while s2[cur-ct[cur]]==s2[cur+ct[cur]]:
|
||||||
|
ct[cur]+=1
|
||||||
|
if cur+ct[cur] > mid+ct[mid]:mid = cur
|
||||||
|
mx = max(ct)
|
||||||
|
idxs = [i for i,j in enumerate(ct) if j == mx]
|
||||||
|
p = idxs[0]
|
||||||
|
for i in idxs:
|
||||||
|
if s2[i]=='#':p = i
|
||||||
|
rst =s2[p-mx+1:p+mx].replace('#','')
|
||||||
|
return rst
|
||||||
|
|
46
codes/markov.py
Normal file
46
codes/markov.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
from random import randint
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class markov:
|
||||||
|
def __init__(self,txt):
|
||||||
|
self.words= self.clean(txt)
|
||||||
|
self.dic = self.getDic(self.words)
|
||||||
|
def clean(self,text):
|
||||||
|
text = text.replace("\n", " ");
|
||||||
|
text = text.replace("\"", "");
|
||||||
|
|
||||||
|
# 保证每个标点符号都和前面的单词在一起
|
||||||
|
# 这样不会被剔除,保留在马尔可夫链中
|
||||||
|
punctuation = [',', '.', ';',':']
|
||||||
|
for symbol in punctuation:
|
||||||
|
text = text.replace(symbol, symbol+" ");
|
||||||
|
|
||||||
|
return re.split(' +',text)
|
||||||
|
|
||||||
|
def getDic(self,words):
|
||||||
|
dic = {}
|
||||||
|
end = len(words)
|
||||||
|
for i in range(1,end):
|
||||||
|
if words[i-1] not in dic:
|
||||||
|
dic[words[i-1]] = {words[i]:1}
|
||||||
|
elif words[i] not in dic[words[i-1]]:
|
||||||
|
dic[words[i-1]][words[i]] = 1
|
||||||
|
else: dic[words[i-1]][words[i]] +=1
|
||||||
|
return dic
|
||||||
|
def getSum(self,dic):
|
||||||
|
if '%size' not in dic:
|
||||||
|
dic['%size'] = sum(list(dic.values()))
|
||||||
|
return dic['%size']
|
||||||
|
def nextWord(self,word):
|
||||||
|
k = randint(1,self.getSum(self.dic[word]))
|
||||||
|
for i,j in self.dic[word].items():
|
||||||
|
k-=j
|
||||||
|
if k<=0:return i
|
||||||
|
def genSentence(self,begin = 'I',length = 30):
|
||||||
|
li = [begin]
|
||||||
|
nextWord= begin
|
||||||
|
for i in range(1,length):
|
||||||
|
nextWord= self.nextWord(nextWord)
|
||||||
|
li.append(nextWord)
|
||||||
|
return ' '.join(li)
|
BIN
codes/sort/__pycache__/quickSort.cpython-35.pyc
Normal file
BIN
codes/sort/__pycache__/quickSort.cpython-35.pyc
Normal file
Binary file not shown.
72
codes/sort/heapSort.py
Normal file
72
codes/sort/heapSort.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
from functools import partial
|
||||||
|
class heap:
|
||||||
|
def __init__(self,lst,reverse = False):
|
||||||
|
self.data= heapify(lst,reverse)
|
||||||
|
self.cmp = partial(lambda i,j,r:cmp(self.data[i],self.data[j],r),r= reverse)
|
||||||
|
def getTop(self):
|
||||||
|
return self.data[0]
|
||||||
|
def __getitem__(self,idx):
|
||||||
|
return self.data[idx]
|
||||||
|
def __bool__(self):
|
||||||
|
return self.data != []
|
||||||
|
def popTop(self):
|
||||||
|
ret = self.data[0]
|
||||||
|
n = len(self.data)
|
||||||
|
cur = 1
|
||||||
|
while cur * 2<=n:
|
||||||
|
chd = cur-1
|
||||||
|
r_idx = cur*2
|
||||||
|
l_idx = r_idx-1
|
||||||
|
if r_idx==n:
|
||||||
|
self.data[chd] = self.data[l_idx]
|
||||||
|
break
|
||||||
|
j = l_idx if self.cmp(l_idx,r_idx)<0 else r_idx
|
||||||
|
self.data[chd] = self.data[j]
|
||||||
|
cur = j+1
|
||||||
|
self.data[cur-1] = self.data[-1]
|
||||||
|
self.data.pop()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def addNode(self,val):
|
||||||
|
self.data.append(val)
|
||||||
|
self.data = one_heapify(len(self.data)-1)
|
||||||
|
|
||||||
|
|
||||||
|
def cmp(n1,n2,reverse=False):
|
||||||
|
fac = -1 if reverse else 1
|
||||||
|
if n1 < n2: return -fac
|
||||||
|
elif n1 > n2: return fac
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def heapify(lst,reverse = False):
|
||||||
|
for i in range(len(lst)):
|
||||||
|
lst = one_heapify(lst,i,reverse)
|
||||||
|
return lst
|
||||||
|
def one_heapify(lst,cur,reverse = False):
|
||||||
|
cur +=1
|
||||||
|
while cur>1:
|
||||||
|
chd = cur-1
|
||||||
|
prt = cur//2-1
|
||||||
|
if cmp(lst[prt],lst[chd],reverse)<0:
|
||||||
|
break
|
||||||
|
lst[prt],lst[chd] = lst[chd], lst[prt]
|
||||||
|
cur = prt+1
|
||||||
|
return lst
|
||||||
|
def heapSort(lst,reverse = False):
|
||||||
|
lst = lst.copy()
|
||||||
|
hp = heap(lst,reverse)
|
||||||
|
ret = []
|
||||||
|
while hp:
|
||||||
|
ret.append(hp.popTop())
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from random import randint
|
||||||
|
n = randint(10,20)
|
||||||
|
lst = [randint(0,100) for i in range(n)]
|
||||||
|
print('random : ', lst)
|
||||||
|
print('small-heap: ', heapify(lst))
|
||||||
|
print('big-heap : ', heapify(lst,True))
|
||||||
|
print('ascend : ', heapSort(lst))
|
||||||
|
print('descend : ', heapSort(lst,True))
|
95
codes/sort/quickSort.py
Normal file
95
codes/sort/quickSort.py
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
def quickSort(lst):
|
||||||
|
'''A optimized version of Hoare partition'''
|
||||||
|
def partition(a,b):
|
||||||
|
pivot = lst[a]
|
||||||
|
while a!=b:
|
||||||
|
while a<b and lst[b]>pivot: b-=1
|
||||||
|
if a<b:
|
||||||
|
lst[a] = lst[b]
|
||||||
|
a+=1
|
||||||
|
while a<b and lst[a]<pivot: a+=1
|
||||||
|
if a<b:
|
||||||
|
lst[b] = lst[a]
|
||||||
|
b-=1
|
||||||
|
lst[a] = pivot
|
||||||
|
return a
|
||||||
|
def _sort(a,b):
|
||||||
|
if a>=b:return
|
||||||
|
mid = (a+b)//2
|
||||||
|
# 三数取中值置于第一个作为 pivot
|
||||||
|
if (lst[a]<lst[mid]) ^ (lst[b]<lst[mid]): lst[a],lst[mid] = lst[mid],lst[a] # lst[mid] 为中值
|
||||||
|
if (lst[a]<lst[b]) ^ (lst[b]>lst[mid]): lst[a],lst[b] = lst[b],lst[a] # lst[b] 为中值
|
||||||
|
i = partition(a,b)
|
||||||
|
_sort(a,i-1)
|
||||||
|
_sort(i+1,b)
|
||||||
|
_sort(0,len(lst)-1)
|
||||||
|
return lst
|
||||||
|
def quickSort2(lst):
|
||||||
|
'''A version of partition from <Introduction of Algorithm>, a little bit slow'''
|
||||||
|
def partition(a,b):
|
||||||
|
pivot = lst[b]
|
||||||
|
j = a-1
|
||||||
|
for i in range(a,b):
|
||||||
|
if lst[i]<=pivot:
|
||||||
|
j+=1
|
||||||
|
if i!=j: lst[i], lst[j] = lst[j], lst[i]
|
||||||
|
lst[j+1],lst[b] = lst[b],lst[j+1]
|
||||||
|
return j+1
|
||||||
|
def _sort(a,b):
|
||||||
|
if a>=b:return
|
||||||
|
mid = (a+b)//2
|
||||||
|
# 三数取中值置于第一个作为 pivot
|
||||||
|
if (lst[a]<lst[mid]) ^ (lst[b]<lst[mid]): lst[b],lst[mid] = lst[mid],lst[b] # lst[mid] 为中值
|
||||||
|
if (lst[a]>lst[b]) ^ (lst[a]>lst[mid]): lst[a],lst[b] = lst[b],lst[a] # lst[b] 为中值
|
||||||
|
i = partition(a,b)
|
||||||
|
_sort(a,i-1)
|
||||||
|
_sort(i+1,b)
|
||||||
|
|
||||||
|
_sort(0,len(lst)-1)
|
||||||
|
return lst
|
||||||
|
def quickSort3(lst):
|
||||||
|
'''A rear recursive optimization version'''
|
||||||
|
def partition(a,b):
|
||||||
|
pivot = lst[b]
|
||||||
|
j = a-1
|
||||||
|
for i in range(a,b):
|
||||||
|
if lst[i]<=pivot:
|
||||||
|
j+=1
|
||||||
|
if i!=j: lst[i], lst[j] = lst[j], lst[i]
|
||||||
|
lst[j+1],lst[b] = lst[b],lst[j+1]
|
||||||
|
return j+1
|
||||||
|
def _sort(a,b):
|
||||||
|
while a<b:
|
||||||
|
mid = (a+b)//2
|
||||||
|
# 三数取中值置于第一个作为 pivot
|
||||||
|
if (lst[a]<lst[mid]) ^ (lst[b]<lst[mid]): lst[b],lst[mid] = lst[mid],lst[b] # lst[mid] 为中值
|
||||||
|
if (lst[a]>lst[b]) ^ (lst[a]>lst[mid]): lst[a],lst[b] = lst[b],lst[a] # lst[b] 为中值
|
||||||
|
i = partition(a,b)
|
||||||
|
_sort(a,i-1)
|
||||||
|
a = i+1
|
||||||
|
_sort(0,len(lst)-1)
|
||||||
|
return lst
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
def timer(func,lst,n=100):
|
||||||
|
t = time()
|
||||||
|
for i in range(n):func(lst)
|
||||||
|
t = time()-t
|
||||||
|
print('{}: {}s'.format(func.__name__,t))
|
||||||
|
return t
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from random import randint
|
||||||
|
print('5000 items, repeat 100 times for each')
|
||||||
|
lst = [randint(0,100) for i in range(5000)]
|
||||||
|
timer(quickSort,lst.copy())
|
||||||
|
timer(quickSort2,lst.copy())
|
||||||
|
timer(quickSort3,lst.copy())
|
||||||
|
|
||||||
|
lst = [randint(0,100) for i in range(15)]
|
||||||
|
print(lst)
|
||||||
|
print(quickSort(lst.copy()))
|
||||||
|
print(quickSort2(lst.copy()))
|
||||||
|
print(quickSort3(lst.copy()))
|
||||||
|
|
||||||
|
|
40
codes/sort/radixSort.py
Normal file
40
codes/sort/radixSort.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
def radixSort(lst,radix=10):
|
||||||
|
ls = [[] for i in range(radix)]
|
||||||
|
mx = max(lst)
|
||||||
|
weight = 1
|
||||||
|
while mx >= weight:
|
||||||
|
for i in lst:
|
||||||
|
ls[(i // weight)%radix].append(i)
|
||||||
|
weight *= radix
|
||||||
|
lst = sum(ls,[])
|
||||||
|
ls = [[] for i in range(radix)]
|
||||||
|
return lst
|
||||||
|
|
||||||
|
def countSort(lst,mn,mx):
|
||||||
|
mark = [0]*(mx-mn+1)
|
||||||
|
for i in lst:
|
||||||
|
mark[i-mn]+=1
|
||||||
|
ret =[]
|
||||||
|
for n,i in enumerate(mark):
|
||||||
|
ret +=[n+mn]*i
|
||||||
|
return ret
|
||||||
|
|
||||||
|
from quickSort import quickSort
|
||||||
|
from time import time
|
||||||
|
from random import randint
|
||||||
|
def timer(funcs,span,num=1000000):
|
||||||
|
lst = [randint(0,span) for i in range(num)]
|
||||||
|
print('range({}), {} items'.format(span,num))
|
||||||
|
for func in funcs:
|
||||||
|
data = lst.copy()
|
||||||
|
t = time()
|
||||||
|
func(data)
|
||||||
|
t = time()-t
|
||||||
|
print('{}: {}s'.format(func.__name__,t))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
timer([quickSort,radixSort,sorted],1000000000000,1000)
|
||||||
|
timer([quickSort,radixSort,sorted],10000,100000)
|
||||||
|
lst = [randint(0,100) for i in range(1000)]
|
||||||
|
print(countSort(lst,0,100)==sorted(lst))
|
0
codes/sort/res.txt
Normal file
0
codes/sort/res.txt
Normal file
37
codes/sort/select.py
Normal file
37
codes/sort/select.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
from random import randint
|
||||||
|
def select(lst,i):
|
||||||
|
lst = lst.copy()
|
||||||
|
def partition(a,b):
|
||||||
|
pivot = lst[a]
|
||||||
|
while a<b:
|
||||||
|
while a<b and lst[b]>pivot: b-=1
|
||||||
|
if a<b:
|
||||||
|
lst[a] = lst[b]
|
||||||
|
a+=1
|
||||||
|
while a<b and lst[a]<pivot: a+=1
|
||||||
|
if a<b:
|
||||||
|
lst[b] = lst[a]
|
||||||
|
b-=1
|
||||||
|
lst[a]= pivot
|
||||||
|
return a
|
||||||
|
|
||||||
|
def _select(a,b):
|
||||||
|
if a>=b: return lst[a]
|
||||||
|
# randomized select
|
||||||
|
n = randint(a,b)
|
||||||
|
lst[a],lst[n] = lst[n],lst[a]
|
||||||
|
pos = partition(a,b)
|
||||||
|
if pos>i:
|
||||||
|
return _select(a,pos-1)
|
||||||
|
elif pos<i:
|
||||||
|
return _select(pos+1,b)
|
||||||
|
else:return lst[pos]
|
||||||
|
return _select(0,len(lst)-1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
lst = [randint(0,1000) for i in range(100)]
|
||||||
|
st = sorted(lst)
|
||||||
|
for i in range(10):
|
||||||
|
n = randint(0,99)
|
||||||
|
print('select {}th: \nexpect: {}\ngot: {}'.format(n,st[n],select(lst,n)))
|
12
codes/sort/shellSort.py
Normal file
12
codes/sort/shellSort.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
def shellSort(s,inc=None):
|
||||||
|
if inc is None:inc = [1,3,5,7,11,13,17,19]
|
||||||
|
num = len(s)
|
||||||
|
inc.sort(reverse=True)
|
||||||
|
for i in inc:
|
||||||
|
for j in range(i,num):
|
||||||
|
cur = j
|
||||||
|
while cur>=i and s[j] > s[cur-i]:
|
||||||
|
s[cur] = s[cur-i]
|
||||||
|
cur-=i
|
||||||
|
s[cur] = s[j]
|
||||||
|
return s
|
56
codes/sort/sort.py
Normal file
56
codes/sort/sort.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
from functools import total_ordering
|
||||||
|
|
||||||
|
@total_ordering
|
||||||
|
class node:
|
||||||
|
def __init__(self,val,left=None,right=None):
|
||||||
|
self.val=val
|
||||||
|
self.frequency = 1
|
||||||
|
self.left=left
|
||||||
|
self.right=right
|
||||||
|
def __lt__(self,x):
|
||||||
|
return self.val<x.val
|
||||||
|
def __eq__(self,x):
|
||||||
|
return self.val==x.val
|
||||||
|
def inc(self):
|
||||||
|
self.val+=1
|
||||||
|
def dec(self):
|
||||||
|
self.val-=1
|
||||||
|
def incFreq(self):
|
||||||
|
self.frequency +=1
|
||||||
|
def decFreq(self):
|
||||||
|
self.frequency -=1
|
||||||
|
|
||||||
|
class binaryTree:
|
||||||
|
def __init__(self,reverse = True):
|
||||||
|
self.reverse = reverse
|
||||||
|
self.data=None
|
||||||
|
def cmp(self,n1,n2):
|
||||||
|
ret=0
|
||||||
|
if n1 < n2: ret=-1
|
||||||
|
if n1 > n2: ret= 1
|
||||||
|
return ret * -1 if self.reverse else ret
|
||||||
|
def addNode(self,nd):
|
||||||
|
def _add(prt,chd):
|
||||||
|
if self.cmp(prt,chd)==0:
|
||||||
|
prt.incFreq()
|
||||||
|
return
|
||||||
|
if self.cmp(prt,chd)<0:
|
||||||
|
|
||||||
|
if not isinstance(nd,node):nd=node(nd)
|
||||||
|
if not self.root :
|
||||||
|
self.root=node(val)
|
||||||
|
else:
|
||||||
|
if self.root == val:
|
||||||
|
self.root.incfreq()
|
||||||
|
else:
|
||||||
|
cur = self.root
|
||||||
|
def build(self,lst):
|
||||||
|
dic = {}
|
||||||
|
for i in lst:
|
||||||
|
if i in dic:
|
||||||
|
dic[i].incFreq()
|
||||||
|
else:
|
||||||
|
dic[i] = node(i)
|
||||||
|
self.data =list( dic.values())
|
||||||
|
|
||||||
|
|
69
codes/steganography_to_do.py
Normal file
69
codes/steganography_to_do.py
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
from PIL import Image
|
||||||
|
from skimage import color
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import math
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('picture')
|
||||||
|
parser.add_argument('-f','file')
|
||||||
|
parser.add_argument('-s','string')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
PIC = args.picture
|
||||||
|
FILE = args.file
|
||||||
|
STR = args.string
|
||||||
|
|
||||||
|
|
||||||
|
class steganography:
|
||||||
|
def __init__(self,picture):
|
||||||
|
self.pic = poicture
|
||||||
|
|
||||||
|
def handlePixel(self,target,attach):
|
||||||
|
'''对一个像素进行隐写 ,attach是要处理的数值,允许在0~9'''
|
||||||
|
a,b,c = target
|
||||||
|
pa,pb,pc = attach
|
||||||
|
return a%10+pa,b%10+pb,c%10+pc
|
||||||
|
def d2n(self,n,base=16):
|
||||||
|
''' num of base_n(n<36) to decimal'''
|
||||||
|
dic = {i:chr(i+ord('0')) for i in range(10)}
|
||||||
|
if base>10:
|
||||||
|
dic.update({i+10:chr(i+ord('A')) for i in range(26)})
|
||||||
|
rst=[]
|
||||||
|
while n!=0:
|
||||||
|
i=int(n/base)
|
||||||
|
rst.append(dic[n-i*base])
|
||||||
|
n=i
|
||||||
|
return ''.join(rst[::-1])
|
||||||
|
def changeBody(self,path):
|
||||||
|
self.pic = path
|
||||||
|
def encryptPic(self,content,base =8):
|
||||||
|
'''将bytes内容content隐写到self.picture中 base can be different value, default 8'''
|
||||||
|
body = np .array (Image.open(self.pic))
|
||||||
|
attach = np.array(content)
|
||||||
|
r,c, _ = body.shape
|
||||||
|
ar,ac,_ = attach.shape
|
||||||
|
|
||||||
|
raise Exception('信息量太大,不能隐写在此图片中,换张更大的图片')
|
||||||
|
def encryptStr(self,content):
|
||||||
|
body = np.array (Image.open(self.pic))
|
||||||
|
r,c,d = body.shape
|
||||||
|
btay = bytearray(content)
|
||||||
|
length = len(btay)
|
||||||
|
if length*8 > (r-1)*c:raise Exception('信息量太大,不能隐写在此图片中,换张更大的图片')
|
||||||
|
def getContent(self,file=None,s=None):
|
||||||
|
'''get the bytes , file is prior to str'''
|
||||||
|
byte = b''
|
||||||
|
if not file:
|
||||||
|
if not s:
|
||||||
|
s = input('输入要隐写的信息')
|
||||||
|
byte = encode(STR,'utf-8')
|
||||||
|
else:byte = open(FILE,'wb').read()
|
||||||
|
return byte
|
||||||
|
|
||||||
|
if __name__ =='__main__':
|
||||||
|
|
||||||
|
PIC
|
BIN
notes/src/recursive-tree.jpg
Normal file
BIN
notes/src/recursive-tree.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
BIN
notes/src/symbol.jpg
Normal file
BIN
notes/src/symbol.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in New Issue
Block a user