目录

pylca

install with bioconda

Adaptation of the the lowest common ancestor (LCA) algorithm originally developed by D. Eppstein (https://www.ics.uci.edu/~eppstein/)

Installation

python setup.py install

Usage

#Example:
parent = {'b':'a','c':'a','d':'a','e':'b','f':'b','g':'f','h':'g','i':'g'}
lcas = {
    ('a','b'):'a',
    ('b','c'):'a',
    ('c','d'):'a',
    ('d','e'):'a',
    ('e','f'):'b',
    ('e','g'):'b',
    ('e','h'):'b',
    ('c','i'):'a',
    ('a','i'):'a',
    ('f','i'):'f',
}

from pylca.pylca import LCA
L = LCA(parent) # RestrictedRangeMin
for k,v in lcas.items():
    print("LCA RestrictedRangeMin", k, L(*k))

from pylca.pylca import LogLCA
L = LogLCA(parent) # LogarithmicRangeMin
for k,v in lcas.items():
    print("LCA LogarithmicRangeMin", k, L(*k))

from pylca.pylca import OfflineLCA
L = OfflineLCA(parent, lcas.keys()) # OfflineLCA
for (p,q),v in lcas.items():
     print("LCA OfflineLCA", (p,q), L[p][q])

TODO

“Some experimentation would be needed to determine how large a query range needs to be to make this faster than computing the min of the range directly, and how much input data is needed to make the linear space version pay off compared to the much simpler LogarithmicRangeMin that it uses as a subroutine.”

关于

基于 Python 实现的最低公共祖先算法库,支持多种 LCA 计算模式

37.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号