code: def search_revert(self, bas, ba, beam_size):
          
          pba = ba.copy()
          self.permute(pba)
          assert(beam_size % 2 == 0)
          half_beam = beam_size / 2
  
          # binary search (pba,ba) in bas
          idx = bisect_left(bas, (pba, ba))
  
          start = int(max(0, idx - half_beam))
          end = int(min(len(bas), idx + half_beam))
  
          res = bas[start:end]
  
          # return the original(unpermuted) keys
          res = [x[1] for x in res]
          return res
docs: ba: query bitarray
          bas: a sorted list of tuples of (permuted bitarray, original bitarray)
          return : query bitarray's beam-size neighbours (unpermuted bitarray)