Add header info

master
mbinary 2018-12-11 15:57:58 +08:00
parent 166cd2737b
commit bbe68d7f4f
14 changed files with 306 additions and 8 deletions

View File

@ -1,3 +1,4 @@
# Algorithm
>Notes and codes for learning algorithm and data structures :smiley:
@ -14,22 +15,24 @@ So,if you wannt to view the notes which contain latex math formulas and are in m
# Index
* [.](.)
* [README.md](./README.md)
* [backtracking](./backtracking)
* [computationalMethod](./computationalMethod)
* [README.md](./computationalMethod/README.md)
* [interplotion.py](./computationalMethod/interplotion.py)
* [iteration.py](./computationalMethod/iteration.py)
* [least_square.py](./computationalMethod/least_square.py)
* [linear_equation.py](./computationalMethod/linear_equation.py)
* [numerical_differential.py](./computationalMethod/numerical_differential.py)
* [numerical_integration.py](./computationalMethod/numerical_integration.py)
* [README.md](./computationalMethod/README.md)
* [solve-linear-by-iteration.py](./computationalMethod/solve-linear-by-iteration.py)
* [tongyu_equation.py](./computationalMethod/tongyu_equation.py)
* [vector_norm.py](./computationalMethod/vector_norm.py)
* [dataStructure](./dataStructure)
* [allOone](./dataStructure/allOone)
* [bTree.py](./dataStructure/bTree.py)
* [binaryHeap.py](./dataStructure/binaryHeap.py)
* [binaryTree.py](./dataStructure/binaryTree.py)
* [bTree.py](./dataStructure/bTree.py)
* [graph](./dataStructure/graph)
* [hashTable.py](./dataStructure/hashTable.py)
* [huffman](./dataStructure/huffman)
@ -40,38 +43,44 @@ So,if you wannt to view the notes which contain latex math formulas and are in m
* [polynomial.cpp](./dataStructure/polynomial.cpp)
* [polynomial.py](./dataStructure/polynomial.py)
* [redBlackTree.py](./dataStructure/redBlackTree.py)
* [redBlackTree0.py](./dataStructure/redBlackTree0.py)
* [splayTree.py](./dataStructure/splayTree.py)
* [trie.py](./dataStructure/trie.py)
* [winnerTree.py](./dataStructure/winnerTree.py)
* [divideAndConquer](./divideAndConquer)
* [min_distance_of_n_points.py](./divideAndConquer/min_distance_of_n_points.py)
* [docs](./docs)
* [README.md](./docs/README.md)
* [algorithm-general.md](./docs/algorithm-general.md)
* [b-tree.md](./docs/b-tree.md)
* [fib-heap.md](./docs/fib-heap.md)
* [graph.md](./docs/graph.md)
* [hashTable.md](./docs/hashTable.md)
* [README.md](./docs/README.md)
* [red-black-tree.md](./docs/red-black-tree.md)
* [sort.md](./docs/sort.md)
* [src](./docs/src)
* [tree.md](./docs/tree.md)
* [dynamicProgramming](./dynamicProgramming)
* [lcs.hs](./dynamicProgramming/lcs.hs)
* [Vec2d.hs](./dynamicProgramming/Vec2d.hs)
* [lcs.py](./dynamicProgramming/lcs.py)
* [matrixChainMultiply.py](./dynamicProgramming/matrixChainMultiply.py)
* [splitStripe.hs](./dynamicProgramming/splitStripe.hs)
* [splitStripe.py](./dynamicProgramming/splitStripe.py)
* [testVec2d.hs](./dynamicProgramming/testVec2d.hs)
* [Vec2d.hs](./dynamicProgramming/Vec2d.hs)
* [math](./math)
* [arrangement.c](./math/arrangement.c)
* [cantor.c](./math/cantor.c)
* [isPrime.py](./math/isPrime.py)
* [num_weight.py](./math/num_weight.py)
* [README.md](./README.md)
* [permute_back_track.py](./math/permute_back_track.py)
* [permute_cantor.c](./math/permute_cantor.c)
* [permute_divide_and_conquer.py](./math/permute_divide_and_conquer.py)
* [permute_next_arrangement.c](./math/permute_next_arrangement.c)
* [primesLEn.hs](./math/primesLEn.hs)
* [search](./search)
* [8Astar.py](./search/8Astar.py)
* [BFS_knight.hs](./search/BFS_knight.hs)
* [binary_search.hs](./search/binary_search.hs)
* [bloomFilter.py](./search/bloomFilter.py)
* [schedule.py](./search/schedule.py)
* [sort](./sort)
* [binaryTree.py](./sort/binaryTree.py)
* [heapSort.py](./sort/heapSort.py)
@ -80,5 +89,15 @@ So,if you wannt to view the notes which contain latex math formulas and are in m
* [select.py](./sort/select.py)
* [shellSort.py](./sort/shellSort.py)
* [string](./string)
* [KMP.py](./string/KMP.py)
* [README.md](./string/README.md)
* [manacher.py](./string/manacher.py)
* [markov.py](./string/markov.py)
* [rabin_karp.py](./string/rabin_karp.py)
* [src](./string/src)
* [sunday.py](./string/sunday.py)
* [utils](./utils)
* [config.py](./utils/config.py)
* [genReadme.py](./utils/genReadme.py)
* [headinfo.py](./utils/headinfo.py)
* [tree.py](./utils/tree.py)

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : intervalTree.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-18 10:48
# Description:
#########################################################################
'''
from redBlackTree import redBlackTree
from functools import total_ordering

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : min_distance_of_n_points.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-24 22:03
# Description:
#########################################################################
'''
from random import randint
from time import time
from functools import total_ordering

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : matrixChainMultiply.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-05 19:09
# Description:
#########################################################################
'''
def matrixChainMultiply(seq):
'''matrix chain multiply, find the optimalest comb to multiply
eg ABCD, (AB)(CD), A((BC)D)

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : permute_back_track.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-25 12:32
# Description:
#########################################################################
'''
def permute(n):
def _util(lst,i):
if i==n:print(lst)

View File

@ -1,3 +1,14 @@
/* mbinary
#########################################################################
# File : permute_cantor.c
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-17 11:25
# Description:
#########################################################################
*/
#include<stdio.h>
//使用康托展开计算全排列, 下面存储的是0!,1!,2!...(n-1)!

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : permute_divide_and_conquer.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-25 12:23
# Description:
#########################################################################
'''
def permute(lst,n):
''' O(n!), optimal'''
if n==1:print(lst)

View File

@ -1,3 +1,14 @@
/* mbinary
#########################################################################
# File : permute_next_arrangement.c
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-17 14:31
# Description:
#########################################################################
*/
#include<stdio.h>
void swap(int*arr,int i,int j)

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : bloomFilter.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-10-17 11:19
# Description:
#########################################################################
'''
from bitarray import bitarray
import mmh3

View File

@ -1,3 +1,14 @@
''' mbinary
#########################################################################
# File : schedule.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-11-30 12:00
# Description:
#########################################################################
'''
'''
回溯全空间搜索, 剪枝优化

31
utils/config.py Normal file
View File

@ -0,0 +1,31 @@
README = r'''
# Algorithm
>Notes and codes for learning algorithm and data structures :smiley:
Some pictures and ideas are from `<<Introduction to Algotithm>>
I use python 3.6+ and c++ to implements them.
Since I used f-Strings in python, you may use python 3.6+ to run the following python scripts.
>>I am still learning new things and this repo is always updating.
# Notice
Currently, Github can't render latex math formulas.
So,if you wannt to view the notes which contain latex math formulas and are in markdown format, you can visit [my blog](https://mbinary.coding.me)
# Index
{index}
'''
HEAD = '''{begin} mbinary
#########################################################################
# File : {name}
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: {ctime}
# Description:
#########################################################################
{end}
'''

32
utils/genReadme.py Normal file
View File

@ -0,0 +1,32 @@
''' mbinary
#########################################################################
# File : genReadme.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-12-11 15:53
# Description:
#########################################################################
'''
# coding: utf-8
from tree import tree
from argparse import ArgumentParser
from config import README
parser = ArgumentParser()
parser.add_argument('-p','--path',default='.',help='path to walk')
parser.add_argument('-f','--fileinclude',action='store_true',help='if has, list files and dirs, else only dirs')
parser.add_argument('-d','--depth', type = int, default = 2)
#获取参数
args = parser.parse_args()
FILE = args.fileinclude
PATH = args.path
DEPTH = args.depth
idxs = tree(PATH,DEPTH,FILE)
s = README.format(index='\n'.join(idxs))
with open('README.md','w') as f:
f.write(s)

63
utils/headinfo.py Normal file
View File

@ -0,0 +1,63 @@
''' mbinary
#########################################################################
# File : headInfo.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-07-08 14:48
# Description:
#########################################################################
'''
import os
import sys
import time
from config import HEAD
count = 0
def handleFile(path):
global count
head = getHead(path)
if head =='': return
with open(path,'r',encoding='utf8',errors='ignore') as f:
s = f.read()
if 'mbinary' in s:
return
count +=1
name = os.path.basename(path)
print('[{count}]: Adding head info to {name}'.format(count=count,name=name))
with open(path,'w') as f:
f.write(head+s)
def getHead(path):
name = os.path.basename(path)
# skip self or hidden file
if name == os.path.basename(__file__) or name[0]=='.': return ''
suf = name[name.rfind('.')+1 :]
begin = end =''
if suf == 'py':
begin = end = "'''"
elif suf in ['c','cc','cpp','java']:
begin,end = '/*','*/'
elif suf == 'sh':
begin = end = '#'
else:return ''
timeStamp = time.localtime(os.stat(path).st_ctime)
ctime = time.strftime('%Y-%m-%d %H:%M',timeStamp)
return HEAD.format(begin=begin,end=end,ctime=ctime,name = name)
def handleDir(dirPath):
gen = os.walk(dirPath)
for path,dirs,files in gen:
for f in files: handleFile(os.path.join(path,f))
if __name__ == '__main__':
works = sys.argv[1:]
if works==[] : works = ['.']
for one in works:
if not os.path.exists(one):
print('[PathError]: {one} not exists'.format(one=one))
continue
if os.path.isdir(one):
handleDir(one)
else:
handleFile(one)

54
utils/tree.py Normal file
View File

@ -0,0 +1,54 @@
''' mbinary
#########################################################################
# File : tree.py
# Author: mbinary
# Mail: zhuheqin1@gmail.com
# Blog: https://mbinary.coding.me
# Github: https://github.com/mbinary
# Created Time: 2018-12-11 15:56
# Description:
#########################################################################
'''
# coding: utf-8
import os
from argparse import ArgumentParser
#命令行输入参数处理
parser = ArgumentParser()
parser.add_argument('-p','--path',default='.',help='path to walk')
parser.add_argument('-f','--fileinclude',action='store_true',help='if has, list files and dirs, else only dirs')
parser.add_argument('-d','--depth', type = int, default = 2)
#获取参数
args = parser.parse_args()
FILE = args.fileinclude
PATH = args.path
DEPTH = args.depth
def mklink(path):
return '* [{name}]({path})'.format(name=os.path.basename(path),path=path)
def clean(paths):
ret = []
for path in paths:
name = os.path.basename(path)
if not ( name.startswith('.') or name.startswith('__')):
ret.append(path)
return ret
def tree(path='.',depth=2,showfile=False):
li = []
if os.path.isdir(path):li = os.listdir(path)
else:li=[path]
items = [os.path.join(path,i) for i in li if not i.startswith('.')]
items = clean(items)
items = sorted(items)
if not showfile: items = [i for i in items if os.path.isdir(i)]
if depth==1:
return [mklink(path)] + [' '*4 + mklink(i) for i in items]
else:
uls = [tree(i,depth-1,showfile) for i in items]
ret = [' '*4 + li for ul in uls for li in ul]
return [mklink(path)] + ret
if __name__ =='__main__':
print('\n'.join(tree(PATH,DEPTH,FILE)))