trait Permutation
Permutation is a precise definition on how elements within index range should be reorganized
Consider ordering a buffer of integers. This could be accomplished it two steps:
- Based on some Ordering, we create a Permutation object, which captures all necessary positions
- Apply permutation to the buffer
val buf = Stream(0, 3, 1, 2, 4).toBuffer
buf.stream.tp // Prints: Stream(0, 3, 1, 2, 4)
// Creating permutation based on given ordering
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.stream.tp // Prints Stream(0, 1, 2, 3, 4)
- Source
- __.scala
class java.lang.Object
trait scala.Matchable
class Any
Def
All changes
All changes
Returns a stream of all changed positions as a tuple: ('old position','new position')
- Source
- __.scala
Apply to mutable Idx
Apply to mutable Idx
Apply all changes to given mutable indexed collection
- Source
- __.scala
Apply to Idx
Apply to Idx
Apply all changes to given indexed collection, with the help of mutation function
- Source
- __.scala
Check for consistency
Check for consistency
It 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