PositionInIndex
PositionInIndex(A,u,I)
PositionInIndex is the positional equivalent of SubIndex.
Finds u in A and returns the integer position of the value along I. If there are duplicates, the largest such position is returned. If u is not found in A, returns 0. PositionInIndex may be necessary when I contains or may contain duplicates, in which case SubIndex isn't sufficient, and without PositionInIndex, there is no easy workaround.
The first parameter is optional. When omitted, PositionInIndex finds u in index I and returns the position of the element in the index (or zero if not found). This has a shorthand syntax @[I=u].
Declaration
PositionInIndex(A:optional Array[I] ; U : atomic ; I : IndexType )
Details
When A is a self-indexed table, PositionInIndex(A,u,A) and Position( U:u, I:A ) are not the same. PositionInIndex(A,u,A) will find the value in the array A, while PositionInIndex( U:u, I:A ) finds u along the index value of A.
When I is a normal index (not a self-indexed table, and not Time within a dynamic loop), then PositionInIndex(I,u,I) and PositionInIndex( U:u, I:I ) are functionally equivalent. However, PositionInIndex( U:u, I:I ) has a speed advantage, particularly when u is an array, or when many lookups along I will be performed. The average lookup time is O(1) for Position(U:u,I:I) but O(size(I)) for PositionInIndex(I,u,I). @[I=u] is also O(1).
See Also
- SubIndex
- @A[I=u]
Enable comment auto-refresher