Documentation for pp_lib

Generated by IDLdoc

single page | use frames     summary     class     fields     routine details     file attributes

./

pp_locate.pro


Routines

top source pp_locate

result = pp_locate(array [, histogram=histogram], unique_values=unique_values [, sorted_values=sorted_values] [, no_sort=no_sort] [, unique_indices=unique_indices] [, sort_indices=sort_indices] [, reverse_sort=reverse_sort], use_pointers=use_pointers, counts=counts)

Locates all the occurrences of all different (unique) values in the input array, similarly to what would be produced by running a where() on each unique value of array, but this is much more efficient, since only one pass is done through the array.

Return value

A hash where the keys are the unique values present in array, and the values are the indices where they occur. See the example below.

Parameters

array in required

An array of any type that can be sorted (integers, reals, strings, etc). If array is sorted, the no_sort keyword can be set, to avoid spending time computing a sort() of array.

Keywords

histogram out optional

A hash where the keys are the unique values present in array, and the values are the number of occurrences in array. unique_values : out, optional An array containing the unique values present in array.

unique_values
sorted_values out optional

A sorted copy of array.

no_sort in optional

If set, pp_locate assumes array is ordered. By default, pp_locate does not make this assumption, and will have to compute a sort() on array. If you know array is sorted, this will save some time. If no_sort is set, but array is not sorted, the results may be incorrect.

unique_indices out optional

The array of indices into the original array of the unique elements.

sort_indices out optional

The array of indices into array to make it ordered: sort_indices=sort(array).

reverse_sort out optional

An array with indices into the sorted version of array, to map the elements back into the original order: while sorted_values=array[sort_indices], sorted_values[reverse_sort]=array.

use_pointers
counts

Examples

Create an array containing several repetitions of a few strings, and locate all the occurences of each unique string:

array=['a','j','kk','a','a','b','zrdc','29','b','29','-19','0'] loc=pp_locate(array,sorted_values=sarray,unique_values=uarray,histogram=h) help,loc ;LOC HASH <ID=140 NELEMENTS=8> print,loc ;zrdc: 6 ;a: 0 3 4 ;j: 1 ;0: 11 ;-19: 10 ;b: 5 8 ;kk: 2 ;29: 7 9 foreach el,uarray do print,el,':',h[el] ;-19: 1 ;0: 1 ;29: 2 ;a: 3 ;b: 2 ;j: 1 ;kk: 1 ;zrdc: 1

Author information

Author:

Paulo Penteado (http://www.ppenteado.net), May/2013

Statistics

Lines:
35 lines
Cyclomatic complexity:
16
Modified cyclomatic complexity:
16

File attributes

Modification date: Wed Jun 29 22:15:28 2016
Lines: 35
Docformat: rst rst