Idx.Permutation

Permutation is a precise definition on how elements within range should be reorganized

Consider ordering a buffer of integers. This could be accomplished it two steps:

   1. Based on some Ordering, we create a [[Permutation]] object, which captures all necessary repositions
   2. Apply permutation to the buffer

```
   val buf = ~~(0, 3, 1, 2, 4).toBuffer

   buf.~.tp // Prints:  ~(0, 3, 1, 2, 4)

   // Creating permutation based on comparator
   val p = Idx.Permutation.sorting(buffer)

   p.tp               // Prints: Permutation{range=1 <>> 4,(1,3)(2,1)(3,2)}

   p.reposition(buf)  // Applying permutation

   buf.~.tp           // Prints ~(0, 1, 2, 3, 4)
 ```
Source
__.scala
class java.lang.Object
trait scala.Matchable
class Any

Def

def mutate(pos: Int): Int

New index

New index

Given current position, returns new position

Source
__.scala
@scala.annotation.targetName("mutation_Stream")
def mutation_~: ~[(Int, Int)]

All changes

All changes

Returns a stream of all changed positions as a tuple: (, )

Source
__.scala

Range of change

Range of change

Range of indexes which changed

Source
__.scala

New positions

New positions

Returns a list of new positions within the range

 // Repositioning range from 3 to 6 r reverse indexes = 6,5,4,3

 val r = Idx.Permutation(3 <> 6, Ints(6, 5, 4, 3))

 r tp  // Prints: Permutation{range=3 <>> 7,(3,6)(4,5)(5,4)(6,3)}
Source
__.scala
def reposition[T](l: Idx.Mutable[T]): Unit

Apply to mutable Idx

Apply to mutable Idx

Apply all changes to given mutable indexed collection

Source
__.scala
def reposition[T](l: Idx[T], update: (Int, T) => Unit): Unit

Apply to Idx

Apply to Idx

Apply all changes to given indexed collection, with the help of mutation function

Source
__.scala
def validate: Unit

Check for consistency

Check for consistency

If is possible to create inconsistent Permutation. For example, the same position could be changed twice, etc.

This operation will throw an exception if inconsistency found

Source
__.scala