Difference between revisions of "PositionInIndex"

Line 2: Line 2:
 
= PositionInIndex(''A'',u,I) =
 
= PositionInIndex(''A'',u,I) =
  
PositionInIndex is the positional equivalent of [[SubIndex]].   
+
'''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.   
+
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].   
+
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 =
 
= Declaration =
Line 13: Line 13:
 
= Details =
 
= 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 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 Position(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).  @[I=u] is also O(1).
  
  

Revision as of 06:19, 14 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.