Difference between revisions of "PositionInIndex"

(hyperlink to @)
Line 15: Line 15:
 
When A is a self-indexed table, PositionInIndex(A,u,A) and PositionInIndex( 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 A is a self-indexed table, PositionInIndex(A,u,A) and PositionInIndex( 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 PositionInIndex(U:u,I:I) but O([[Size]](I)) for PositionInIndex(I,u,I).  @[I=u] is also O(1).
+
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 [[PositionInIndex]](U:u,I:I) but O([[Size]](I)) for [[PositionInIndex]](I,u,I).  [[Index Position Operator::@|@[I=u] ]] is also O(1).
  
  
Line 21: Line 21:
  
 
* [[SubIndex]]
 
* [[SubIndex]]
* @[I=u]
+
* [[Index Position Operator::@|@[I=u] ]]

Revision as of 19:53, 19 February 2007

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 PositionInIndex( 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 PositionInIndex(U:u,I:I) but O(Size(I)) for PositionInIndex(I,u,I). @[I=u] is also O(1).


See Also

Comments


You are not allowed to post comments.