Rankers

sage.combinat.ranker.from_list(l)

Returns a ranker from the list l.

INPUT:

  • l - a list

OUTPUT:

  • [rank, unrank] - functions

EXAMPLES:

sage: import sage.combinat.ranker as ranker
sage: l = [1,2,3]
sage: r,u = ranker.from_list(l)
sage: r(1)
0
sage: r(3)
2
sage: u(2)
3
sage: u(0)
1
sage.combinat.ranker.on_fly()

Returns a pair of enumeration functions rank / unrank.

rank assigns on the fly an integer, starting from 0, to any object passed as argument. The object should be hashable. unrank is the inverse function; it returns None for indices that have not yet been assigned.

EXAMPLES:

sage: [rank, unrank] = sage.combinat.ranker.on_fly()
sage: rank('a')
0
sage: rank('b')
1
sage: rank('c')
2
sage: rank('a')
0
sage: unrank(2)
'c'
sage: unrank(3)
sage: rank('d')
3
sage: unrank(3)
'd'

Todo

add tests as in combinat::rankers

sage.combinat.ranker.rank_from_list(l)

Returns a rank function given a list l.

EXAMPLES:

sage: import sage.combinat.ranker as ranker
sage: l = [1,2,3]
sage: r = ranker.rank_from_list(l)
sage: r(1)
0
sage: r(3)
2
sage.combinat.ranker.unrank_from_list(l)

Returns an unrank function from a list.

EXAMPLES:

sage: import sage.combinat.ranker as ranker
sage: l = [1,2,3]
sage: u = ranker.unrank_from_list(l)
sage: u(2)
3
sage: u(0)
1

Previous topic

Tools

This Page