Perform a swap operation on a sequence of tokens, exhaustively swapping all tokens up to the maximum specified distance. This is a subset of all permutations.
499410
def swap(tokens, maxdist=2):
    """"""
    assert maxdist >= 2
    tokens = list(tokens)
    if maxdist > len(tokens):
        maxdist = len(tokens)
    l = len(tokens)
    for i in range(0,l - 1):
        for permutation in permutations(tokens[i:i+maxdist]):
            if permutation != tuple(tokens[i:i+maxdist]):
                newtokens = tokens[:i]
                newtokens += permutation
                newtokens += tokens[i+maxdist:]
                yield newtokens
        if maxdist == len(tokens):
            break
410654
def _swap(self, class1, class2, a):
        """"""
        ss1 = self._ss(class1)
        ss2 = self._ss(class2)
        tss1 = ss1 + ss2
        class1c = copy.copy(class1)
        class2c = copy.copy(class2)
        class1c.remove(a)
        class2c.append(a)
        ss1 = self._ss(class1c)
        ss2 = self._ss(class2c)
        tss2 = ss1 + ss2
        if tss1 < tss2:
            return False
        else:
            return True
812738
private void moveIndexesToNextCombination()
    {
        for (int i = currentIndexes.length - 1, j = list.size() - 1; i >= 0; i--, j--)
        {
            if (currentIndexes[i] != j)
            {
                currentIndexes[i]++;
                for (int k = i + 1; k < currentIndexes.length; k++)
                {
                    currentIndexes[k] = currentIndexes[k - 1] + 1;
                }
                return;
            }
        }
        // otherwise, we are all done:
        currentIndexes = null;
    }
1002839
public static void shuffle(int[] intArray) {
		int swapPlace = -1;

		for(int i = 0; i < intArray.length; i++) {
			swapPlace = (int) (Math.random() * (intArray.length - 1 ));
			XORSwap.swap(intArray, i, swapPlace);
		}
	}
264280
function swap(bytes, offset, index) {
  offset--;
  for(let x = 0; x < offset; x++) {
    /** @type {*} */
    let theByte = bytes[index + x];
    bytes[index + x] = bytes[index + offset];
    bytes[index + offset] = theByte;
    offset--;
  }
}
884810
def permute_iter(elements):
    
    if len(elements) <= 1:
        yield elements
    else:
        for perm in permute_iter(elements[1:]):
            for i in range(len(elements)):
                yield perm[:i] + elements[0:1] + perm[i:]
184565
private static void reverse(int first, int last, Swapper swapper) {
	// no more needed since manually inlined
	while (first < --last) {
		swapper.swap(first++,last);
	}
}
1272108
public static Object swap(Object array, int index1, int index2) {
		if (isEmpty(array)) {
			throw new IllegalArgumentException("Array must not empty !");
		}
		Object tmp = get(array, index1);
		Array.set(array, index1, Array.get(array, index2));
		Array.set(array, index2, tmp);
		return array;
	}
748485
def swap_word_order(source):
    
    assert len(source) % 4 == 0
    words = "I" * (len(source) // 4)
    return struct.pack(words, *reversed(struct.unpack(words, source)))
413797
public Mutations<S> move(int offset) {
        int[] newMutations = new int[mutations.length];
        for (int i = 0; i < mutations.length; ++i)
            newMutations[i] = Mutation.move(mutations[i], offset);
        return new Mutations<S>(alphabet, newMutations, true);
    }
621716
private static final void swap(double[] data, int a, int b) {
    double tmp = data[a];
    data[a] = data[b];
    data[b] = tmp;
  }
163202
function swap(sArray, location) {
	location = location % sArray.length;
	var ref = [ sArray[location] , sArray[0] ];
	sArray[0] = ref[0];
	sArray[location] = ref[1];
	return sArray;
}
250346
public void swap( Element<T> a , Element<T> b ) {
		if (a.next == b) {
			if( a.previous != null ) {
				a.previous.next = b;
			}
			if( b.next != null ) {
				b.next.previous = a;
			}
			Element<T> tmp = a.previous;
			a.previous = b;
			a.next = b.next;
			b.previous = tmp;
			b.next = a;
			if( first == a )
				first = b;
			if( last == b )
				last = a;
		} else if (a.previous == b) {
			if( a.next != null ) {
				a.next.previous = b;
			}
			if( b.previous != null ) {
				b.previous.next = a;
			}
			Element<T> tmp = a.next;
			a.next = b;
			a.previous = b.previous;
			b.previous = a;
			b.next = tmp;

			if( first == b )
				first = a;
			if( last == a )
				last = b;
		} else {
			if (a.next != null) {
				a.next.previous = b;
			}
			if (a.previous != null) {
				a.previous.next = b;
			}
			if (b.next != null) {
				b.next.previous = a;
			}
			if (b.previous != null) {
				b.previous.next = a;
			}
			Element<T> tempNext = b.next;
			Element<T> tempPrev = b.previous;
			b.next = a.next;
			b.previous = a.previous;
			a.next = tempNext;
			a.previous = tempPrev;

			if (a.next == null)
				last = a;
			else if (b.next == null)
				last = b;
			if (a.previous == null)
				first = a;
			else if (b.previous == null)
				first = b;
		}
	}
197442
def _swap_slice_indices(self, slc, make_slice=False):
        '''
        '''
        try:
            start = slc.start
            stop = slc.stop
            slc_step = slc.step
        except AttributeError:
            if make_slice:
                if slc < 0:
                    slc += self.length()
                return slice(slc, slc + 1)
            else:
                return slc
        else:
            if not start and start != 0:
                slc_stop = self.length()
            elif start < 0:
                slc_stop = self.length() + start + 1
            else:
                slc_stop = start + 1
            if not stop and stop != 0:
                slc_start = 0
            elif stop < 0:
                slc_start = self.length() + stop
            else:
                slc_start = stop
            return slice(slc_start, slc_stop, slc_step)
1117301
public void swap(int i, int j) {
    checkBounds(i);
    checkBounds(j);

    if (i == j)
      return;

    copier.copy(tmp, offset(i));
    unsafe.copyMemory(null, offset(j), null, offset(i), elementSpacing);
    unsafe.copyMemory(tmp, firstFieldOffset, null, offset(j), elementSize);
  }
384551
public static void swap(final int[] arr, final int a, final int b, final int n) {
        for (int i = 0; i < n; ++i)
            swap(arr, a + i, b + i);
    }
334025
private static void swap(Object[] w, int a, int b) {

        Object t = w[a];

        w[a] = w[b];
        w[b] = t;
    }