I am trying to develop a method for finding the orderd rank of a particular sequence in the following lists.
a = list(sorted(itertools.combinations(range(0,5),3)))
b = list(sorted(itertools.permutations(range(0,5),3)))
a
represents a list of elemnts of a combinatorial number system so the formula for rank is pretty straight forward.
What I need are 2 function magic_rank_1 and magic_rank_2 which have the following definitions
def magic_rank_1(perm_item,permutation_list_object):
## permutation_list_object is actually b
return list_object.index(perm_item)
def magic_rank_2(perm_item,permutation_list_object,combination_list_object):
## permutation_list_object is actually b and combination_list_object is actually a
return combination_list_object.index(tuple(sorted(perm_item)))
So basically magic_rank_2((0,1,2),b,a) = magic_rank_2((2,0,1),b,a)
Sounds easy.. but i have a few restrictions.
- I cant use the indexof function because I cannot afford to search lists >100000000 items for every item
- I need magic_rank_1 and magic_rank_2 to be purely mathematical without using any sort function or comparison functions or search function. All the information I will have is the tuple whose rank needs to be identified and the last letter of my alphabet (in this case that will be 5)
- magic rank 2 need not be a number between 0 and k-1 when k = len(a) as long as it is a unique number between 0 and 2^(ceiling((max_alphabet/2)+1))
I know magic_rank_1 can be calculated by something similar to this but there is a difference ,there every letter of the input alphabet is used, in my case it is a subset
Lastly yes this is supposed to be a substitute for a hashing function, currently using a hashing function but I am not taking advantage of the fact that magic_rank_2((0,1,2),b,a) = magic_rank_2((2,0,1),b,a)
. If i can it will reduce my storage space requirements significantly as the length of my sequences is actually 5 , so if I can calculate a method for magic_rank_2 I reduce my storage requirement to 1% of current requirement
UPDATE - For magic_rank_2 there should be no comparison operation between elements of the tuple, i.e no sorting, min,max etc
that only makes the algorithm less efficient than regular hashing