<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> S-Lang Run-Time Library Reference: Version 1.4.0: Associative Array Functions</TITLE>
<LINK HREF="slangfun-3.html" REL=next>
<LINK HREF="slangfun-1.html" REL=previous>
<LINK HREF="slangfun.html#toc2" REL=contents>
</HEAD>
<BODY>
<A HREF="slangfun-3.html">Next</A>
<A HREF="slangfun-1.html">Previous</A>
<A HREF="slangfun.html#toc2">Contents</A>
<HR>
<H2><A NAME="s2">2. Associative Array Functions</A></H2>

<P>
<H2><A NAME="assoc_delete_key"></A> <A NAME="ss2.1">2.1 <B>assoc_delete_key</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Delete a key from an Associative Array
<DT><B> Usage </B><DD><P><CODE>assoc_delete_key (Assoc_Type a, String_Type k)</CODE>
<DT><B> Description </B><DD><P>The <CODE>assoc_delete_key</CODE> function deletes a key given by <CODE>k</CODE>
from the associative array <CODE>a</CODE>.  If the specified key does not
exist in <CODE>a</CODE>, then this function has no effect.
<DT><B> See Also </B><DD><P><CODE>assoc_key_exists, assoc_get_keys</CODE>
</DL>
<P>
<P>
<H2><A NAME="assoc_get_keys"></A> <A NAME="ss2.2">2.2 <B>assoc_get_keys</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Return all the key names of an Associative Array
<DT><B> Usage </B><DD><P><CODE>String_Type[] assoc_get_keys (Assoc_Type a)</CODE>
<DT><B> Description </B><DD><P>This function returns all the key names of an associative array
<CODE>a</CODE> as an ordinary one dimensional array of strings.  If the
associative array contains no keys, an empty array will be returned.
<DT><B> Example </B><DD><P>The following function computes the number of keys in an associative
array:
<BLOCKQUOTE><CODE>
<PRE>
      define get_num_elements (a)
      {
         return length (assoc_get_keys (a));
      }
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>assoc_get_values, assoc_key_exists, assoc_delete_key, length</CODE>
</DL>
<P>
<P>
<H2><A NAME="assoc_get_values"></A> <A NAME="ss2.3">2.3 <B>assoc_get_values</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Return all the values of an Associative Array
<DT><B> Usage </B><DD><P><CODE>Array_Type assoc_get_keys (Assoc_Type a)</CODE>
<DT><B> Description </B><DD><P>This function returns all the values in the associative array
<CODE>a</CODE> as an array of proper type.  If the associative array
contains no keys, an empty array will be returned.
<DT><B> Example </B><DD><P>Suppose that <CODE>a</CODE> is an associative array of type
<CODE>Integer_Type</CODE>, i.e., it was created via
<BLOCKQUOTE><CODE>
<PRE>
      variable a = Assoc_Type[Integer_Type];
</PRE>
</CODE></BLOCKQUOTE>

The the following may be used to print the values of the array in
ascending order:
<BLOCKQUOTE><CODE>
<PRE>
      static define int_sort_fun (x, y)
      {
         return sign (x - y);
      }
      define sort_and_print_values (a)
      {
         variable i, v;
         
         v = assoc_get_values (a);
         i = array_sort (v, &amp;int_sort_fun);
         v = v[i];
         foreach (v)
           {
              variable vi = ();
              () = fprintf (stdout, "%d\n", vi);
           }
      }
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>assoc_get_values, assoc_key_exists, assoc_delete_key, array_sort</CODE>
</DL>
<P>
<P>
<H2><A NAME="assoc_key_exists"></A> <A NAME="ss2.4">2.4 <B>assoc_key_exists</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Check to see whether a key exists in an Associative Array
<DT><B> Usage </B><DD><P><CODE>Integer_Type assoc_key_exists (Assoc_Type a, String_Type k)</CODE>
<DT><B> Description </B><DD><P>The <CODE>assoc_key_exists</CODE> function may be used to determine whether
or not a specified key <CODE>k</CODE> exists in an associative array <CODE>a</CODE>.
It returns <CODE>1</CODE> if the key exists, or <CODE>0</CODE> if it does not.
<DT><B> See Also </B><DD><P><CODE>assoc_get_keys, assoc_get_values, assoc_delete_key</CODE>
</DL>
<P>
<P>
<P>
<HR>
<A HREF="slangfun-3.html">Next</A>
<A HREF="slangfun-1.html">Previous</A>
<A HREF="slangfun.html#toc2">Contents</A>
</BODY>
</HTML>
