Hi.
I know of no built-in function that does this in PostScript. However, some years back I cooked up something equivalent.
I had an array of values (all unique, which is necessary for this technique to work) that I had to repeatedly process sequentially, but *only* if the array contained a particular value already. What I did was set up a “shadow dictionary” that had as its keys the values from the array, each key associated with the index of that value in the array. (See code below.)
To determine whether a value was in the array, I could do a “known” on the dictionary. Very much faster than a sequential search of the array.
Note that this technique depends on a little-known characteristic of PostScript dictionaries: a dictionary key can be any type of PS object, not just a name or string.
Also note that this technique increases the memory use of the code. A classic case of memory versus speed.
Finally, if all you really want is the position of the object in the array (which was not my case way back when), you don’t really need the array at all. Just use the dictionary with each object (formerly in the array) associated with the appropriate “index” value.
Hope this helps.
- John
===============
Acumen Training
PostScript & PDF
Consulting & Training
www.acumentraining.com
===============
% ======== Cut Here ==================
% The array
/theArray [ 100 27 19 -6 42.8 (Bunny) ] def
% The shadow dict
/theDict theArray length dict def
theDict begin
% Load the dict with the array's values
0 1 theArray length 1 sub {
theArray 1 index get
exch def
} for
end
% This procedure determines whether an object is a member of theArray
% and, if so, returns the object’s index and true; otherwise it returns a false.
/ArrayKnown { % obj => i true | false
theDict exch
2 copy known
{ get true }{ pop false }
ifelse
} bind def
% Now let's try this puppy out...
100 ArrayKnown { = } {(Not here.) = } ifelse
(Bunny) ArrayKnown { = } {(Not here.) = } ifelse
/TweedleDee ArrayKnown { = } {(Not here.) = } ifelse