Difference between revisions of "SubIndex"

m
m
Line 1: Line 1:
 
[[Category:Array-reducing functions]]
 
[[Category:Array-reducing functions]]
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
+
[[Category:Doc Status D]]  
 +
<!-- For Lumina use, do not change -->
 
   
 
   
  
= SubIndex(A,u,I) =
+
== SubIndex(A,u,I) ==
 
Returns the value of index «I» for which array «A» (indexed by «i») is equal to «u». If «u» does not occur in «A», returns [[Null]].  If «u» occurs more than once in «A», it returns the last value of «I» that is equal to «u». If «A» has index(es) in addition to «I», or if the value «u» is an array with other indexes, those indexes also appear in the result.
 
Returns the value of index «I» for which array «A» (indexed by «i») is equal to «u». If «u» does not occur in «A», returns [[Null]].  If «u» occurs more than once in «A», it returns the last value of «I» that is equal to «u». If «A» has index(es) in addition to «I», or if the value «u» is an array with other indexes, those indexes also appear in the result.
  
Line 9: Line 10:
  
  
= Array Abstraction =
+
== Array Abstraction ==
  
 
When «A» has more than one dimension, or «u» is an array, [[SubIndex]] array abstracts according to the standard rules of [[Array Abstraction|array abstraction]].  For example, when «A» contains an index other than I, [[SubIndex]] is applied to each slice of that index, returning the position of «u» in the corresponding slice.  When «u» contains an array of values, the position of each of those values in «A» is returned.
 
When «A» has more than one dimension, or «u» is an array, [[SubIndex]] array abstracts according to the standard rules of [[Array Abstraction|array abstraction]].  For example, when «A» contains an index other than I, [[SubIndex]] is applied to each slice of that index, returning the position of «u» in the corresponding slice.  When «u» contains an array of values, the position of each of those values in «A» is returned.
  
= Examples =
+
== Examples ==
  
 
Let:
 
Let:
Line 94: Line 95:
 
|}
 
|}
  
= See Also =
+
== See Also ==
  
 
* [[PositionInIndex]]
 
* [[PositionInIndex]]
 
* [[Subscript]]
 
* [[Subscript]]

Revision as of 21:29, 26 October 2015


SubIndex(A,u,I)

Returns the value of index «I» for which array «A» (indexed by «i») is equal to «u». If «u» does not occur in «A», returns Null. If «u» occurs more than once in «A», it returns the last value of «I» that is equal to «u». If «A» has index(es) in addition to «I», or if the value «u» is an array with other indexes, those indexes also appear in the result.

SubIndex is the inverse of SubScript. While SubScript maps from the index value to the array element, SubIndex maps from the array element to the index value. SubIndex is not as efficient as SubScript -- while SubScript makes use of a hash-table for constant-time associative lookup, SubIndex must search the array each time for the indicated value, which takes linear time relative to the size of the array.


Array Abstraction

When «A» has more than one dimension, or «u» is an array, SubIndex array abstracts according to the standard rules of array abstraction. For example, when «A» contains an index other than I, SubIndex is applied to each slice of that index, returning the position of «u» in the corresponding slice. When «u» contains an array of values, the position of each of those values in «A» is returned.

Examples

Let:

I → 'a' 'b' 'c' 'd' 'e' 'f'
A → 4 3 2 5 3 1
      
B I
'a' 'b' 'c' 'd' 'e' 'f'
J 1 3 5 2 4 5 3
2 2 1 5 2 3 4
      
K → 1 2 3 4 5
C → 4 2 5 1 3

Then:

SubIndex(A,2,I) → 'c'
SubIndex(A,3,I) → 'e'
SubIndex(A,6,I) → «null»
SubIndex(A,1..5,I) → ['f', 'c', 'e', 'a', 'd']
     SubIndex(A,C,I) →
K → 1 2 3 4 5
'a' 'c' 'd' 'f' 'e'


     SubIndex(B,2,I) →
J → 1 2
'c' 'd'
     SubIndex(B,C,I) →
B K
1 2 3 4 5
J 1 'd' 'c' 'e' «null» 'f'
2 'f' 'd' 'c' 'd' 'e'

See Also

Comments


You are not allowed to post comments.