def get_neighbour_keys(self, bucket_key, k):
<EOL>query_key = bitarray(bucket_key)<EOL>topk = set()<EOL>for i in xrange(len(self.permutes)):<EOL><INDENT>p = self.permutes[i]<EOL>plist = self.permuted_lists[i]<EOL>candidates = p.search_revert(plist, query_key, self.beam_size)<EOL>topk = topk.union(set(candidates))<EOL><DEDENT>topk = list(topk)<EOL>topk = sorted(topk, key=lambda x: self.hamming_distance(x, query_key))<EOL>topk_bin = [x.to01() for x in topk[:k]]<EOL>return topk_bin<EOL>
The computing complexity is O( np*beam*log(np*beam) )
where,
np = number of permutations
beam = self.beam_size

Make sure np*beam is much less than the number of bucket keys,
otherwise we could use brute-force to get the neighbours