1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
3 <!-- SECTION: Programming -->
5 <title>Array API
</title>
6 <meta name='keywords' content='Programming'
>
7 <meta name='creator' content='Mini-XML v2.3'
>
8 <style type='text/css'
><!--
9 h1, h2, h3, p { font-family: sans-serif; text-align: justify; }
10 tt, pre a:link, pre a:visited, tt a:link, tt a:visited { font-weight: bold; color: #7f0000; }
11 pre { font-weight: bold; color: #7f0000; margin-left: 2em; }
12 span.info { background: #000000; border: solid thin #000000; color: #ffffff; font-size: 80%; font-style: italic; font-weight: bold; white-space: nowrap; }
13 h3 span.info { float: right; font-size: 100%; }
14 h1.title, h2.title, h3.title { border-bottom: solid 2px #000000; }
19 "$Id: api-array.shtml 6649 2007-07-11 21:46:42Z mike $"
21 Array API introduction for the Common UNIX Printing System (CUPS).
23 Copyright 2007 by Apple Inc.
24 Copyright 1997-2006 by Easy Software Products, all rights reserved.
26 These coded instructions, statements, and computer programs are the
27 property of Apple Inc. and are protected by Federal copyright
28 law. Distribution and use rights are outlined in the file "LICENSE.txt"
29 which should have been included with this file. If this file is
30 file is missing or damaged, see the license at "http://www.cups.org/".
33 <h2 class='title'
>Introduction
</h2>
35 <p>The CUPS array API provides a high-performance generic array
36 container. The contents of the array container can be sorted and
37 the container itself is designed for optimal speed and memory
38 usage under a wide variety of conditions.
</p>
40 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
41 functions use the array API to efficiently manage large lists of
44 <h2 class='title'
>General Usage
</h2>
46 <p>The
<var><cups/array.h
></var> header file must be
47 included to use the
<tt>cupsArray
</tt> functions.
</p>
49 <p>Programs using these functions must be linked to the CUPS
50 library:
<var>libcups.a
</var>,
<var>libcups.so
.2</var>,
51 <var>libcups
.2.dylib
</var>,
<var>libcups_s.a
</var>, or
52 <var>libcups2.lib
</var> depending on the platform. The following
53 command compiles
<var>myprogram.c
</var> using GCC and the CUPS
57 <kbd>gcc -o myprogram myprogram.c -lcups
</kbd>
60 <h2 class='title'
>Compatibility
</h2>
62 <p>All of these functions require CUPS
1.2 or higher.
</p>
63 <h2 class='title'
>Contents
</h2>
65 <li><a href='#FUNCTIONS'
>Functions
</a></li>
66 <li><a href='#TYPES'
>Types
</a></li>
69 <h2 class='title'
><a name='FUNCTIONS'
>Functions
</a></h2>
71 <li><a href='#cupsArrayAdd'
><tt>cupsArrayAdd()
</tt></a> </li>
72 <li><a href='#cupsArrayClear'
><tt>cupsArrayClear()
</tt></a> </li>
73 <li><a href='#cupsArrayCount'
><tt>cupsArrayCount()
</tt></a> </li>
74 <li><a href='#cupsArrayCurrent'
><tt>cupsArrayCurrent()
</tt></a> </li>
75 <li><a href='#cupsArrayDelete'
><tt>cupsArrayDelete()
</tt></a> </li>
76 <li><a href='#cupsArrayDup'
><tt>cupsArrayDup()
</tt></a> </li>
77 <li><a href='#cupsArrayFind'
><tt>cupsArrayFind()
</tt></a> </li>
78 <li><a href='#cupsArrayFirst'
><tt>cupsArrayFirst()
</tt></a> </li>
79 <li><a href='#cupsArrayGetIndex'
><tt>cupsArrayGetIndex()
</tt></a> <span class='info'
> CUPS
1.3 </span></li>
80 <li><a href='#cupsArrayGetInsert'
><tt>cupsArrayGetInsert()
</tt></a> <span class='info'
> CUPS
1.3 </span></li>
81 <li><a href='#cupsArrayIndex'
><tt>cupsArrayIndex()
</tt></a> </li>
82 <li><a href='#cupsArrayInsert'
><tt>cupsArrayInsert()
</tt></a> </li>
83 <li><a href='#cupsArrayLast'
><tt>cupsArrayLast()
</tt></a> </li>
84 <li><a href='#cupsArrayNew'
><tt>cupsArrayNew()
</tt></a> </li>
85 <li><a href='#cupsArrayNew2'
><tt>cupsArrayNew2()
</tt></a> <span class='info'
> CUPS
1.3 </span></li>
86 <li><a href='#cupsArrayNext'
><tt>cupsArrayNext()
</tt></a> </li>
87 <li><a href='#cupsArrayPrev'
><tt>cupsArrayPrev()
</tt></a> </li>
88 <li><a href='#cupsArrayRemove'
><tt>cupsArrayRemove()
</tt></a> </li>
89 <li><a href='#cupsArrayRestore'
><tt>cupsArrayRestore()
</tt></a> </li>
90 <li><a href='#cupsArraySave'
><tt>cupsArraySave()
</tt></a> </li>
91 <li><a href='#cupsArrayUserData'
><tt>cupsArrayUserData()
</tt></a> </li>
94 <h3 class='title'
><a name='cupsArrayAdd'
>cupsArrayAdd()
</a></h3>
96 <p>Add an element to the array.
97 <p>When adding an element to a sorted array, non-unique elements are
98 appended at the end of the run. For unsorted arrays, the element
99 is inserted at the end of the array.
104 <a href='#cups_array_t'
>cups_array_t
</a> * a,
108 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
109 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
111 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
112 <tr><td><tt>e
</tt></td><td>Element
</td></tr>
113 </tbody></table></div>
115 <p>1 on success,
0 on failure
</p>
117 <h3 class='title'
><a name='cupsArrayClear'
>cupsArrayClear()
</a></h3>
124 <a href='#cups_array_t'
>cups_array_t
</a> * a);
127 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
128 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
130 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
131 </tbody></table></div>
135 <h3 class='title'
><a name='cupsArrayCount'
>cupsArrayCount()
</a></h3>
137 <p>Get the number of elements in the array.
142 <a href='#cups_array_t'
>cups_array_t
</a> * a);
145 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
146 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
148 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
149 </tbody></table></div>
151 <p>Number of elements
</p>
153 <h3 class='title'
><a name='cupsArrayCurrent'
>cupsArrayCurrent()
</a></h3>
155 <p>Return the current element in the array.
160 <a href='#cups_array_t'
>cups_array_t
</a> * a);
163 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
164 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
166 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
167 </tbody></table></div>
171 <h3 class='title'
><a name='cupsArrayDelete'
>cupsArrayDelete()
</a></h3>
173 <p>Free all memory used by the array.
178 <a href='#cups_array_t'
>cups_array_t
</a> * a);
181 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
182 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
184 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
185 </tbody></table></div>
189 <h3 class='title'
><a name='cupsArrayDup'
>cupsArrayDup()
</a></h3>
191 <p>Duplicate the array.
194 <a href='#cups_array_t'
>cups_array_t
</a> *
<br>
196 <a href='#cups_array_t'
>cups_array_t
</a> * a);
199 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
200 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
202 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
203 </tbody></table></div>
205 <p>Duplicate array
</p>
207 <h3 class='title'
><a name='cupsArrayFind'
>cupsArrayFind()
</a></h3>
209 <p>Find an element in the array.
214 <a href='#cups_array_t'
>cups_array_t
</a> * a,
218 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
219 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
221 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
222 <tr><td><tt>e
</tt></td><td>Element
</td></tr>
223 </tbody></table></div>
225 <p>Element found or NULL
</p>
227 <h3 class='title'
><a name='cupsArrayFirst'
>cupsArrayFirst()
</a></h3>
229 <p>Get the first element in the array.
234 <a href='#cups_array_t'
>cups_array_t
</a> * a);
237 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
238 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
240 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
241 </tbody></table></div>
243 <p>First element or NULL
</p>
245 <h3 class='title'
><span class='info'
> CUPS
1.3 </span><a name='cupsArrayGetIndex'
>cupsArrayGetIndex()
</a></h3>
247 <p>Get the index of the current element.
254 <a href='#cups_array_t'
>cups_array_t
</a> * a);
257 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
258 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
260 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
261 </tbody></table></div>
263 <p>Index of the current element
</p>
265 <h3 class='title'
><span class='info'
> CUPS
1.3 </span><a name='cupsArrayGetInsert'
>cupsArrayGetInsert()
</a></h3>
267 <p>Get the index of the last inserted element.
274 <a href='#cups_array_t'
>cups_array_t
</a> * a);
277 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
278 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
280 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
281 </tbody></table></div>
283 <p>Index of the last inserted element
</p>
285 <h3 class='title'
><a name='cupsArrayIndex'
>cupsArrayIndex()
</a></h3>
287 <p>Get the N-th element in the array.
292 <a href='#cups_array_t'
>cups_array_t
</a> * a,
296 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
297 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
299 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
300 <tr><td><tt>n
</tt></td><td>Index into array, starting at
0</td></tr>
301 </tbody></table></div>
303 <p>N-th element or NULL
</p>
305 <h3 class='title'
><a name='cupsArrayInsert'
>cupsArrayInsert()
</a></h3>
307 <p>Insert an element in the array.
308 <p>When inserting an element in a sorted array, non-unique elements are
309 inserted at the beginning of the run. For unsorted arrays, the element
310 is inserted at the beginning of the array.
315 <a href='#cups_array_t'
>cups_array_t
</a> * a,
319 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
320 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
322 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
323 <tr><td><tt>e
</tt></td><td>Element
</td></tr>
324 </tbody></table></div>
326 <p>0 on failure,
1 on success
</p>
328 <h3 class='title'
><a name='cupsArrayLast'
>cupsArrayLast()
</a></h3>
330 <p>Get the last element in the array.
335 <a href='#cups_array_t'
>cups_array_t
</a> * a);
338 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
339 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
341 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
342 </tbody></table></div>
344 <p>Last element or NULL
</p>
346 <h3 class='title'
><a name='cupsArrayNew'
>cupsArrayNew()
</a></h3>
348 <p>Create a new array.
351 <a href='#cups_array_t'
>cups_array_t
</a> *
<br>
353 <a href='#cups_array_func_t'
>cups_array_func_t
</a> f,
357 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
358 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
360 <tr><td><tt>f
</tt></td><td>Comparison function
</td></tr>
361 <tr><td><tt>d
</tt></td><td>User data
</td></tr>
362 </tbody></table></div>
366 <h3 class='title'
><span class='info'
> CUPS
1.3 </span><a name='cupsArrayNew2'
>cupsArrayNew2()
</a></h3>
368 <p>Create a new array with hash.
373 <a href='#cups_array_t'
>cups_array_t
</a> *
<br>
375 <a href='#cups_array_func_t'
>cups_array_func_t
</a> f,
377 <a href='#cups_ahash_func_t'
>cups_ahash_func_t
</a> h,
381 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
382 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
384 <tr><td><tt>f
</tt></td><td>Comparison function
</td></tr>
385 <tr><td><tt>d
</tt></td><td>User data
</td></tr>
386 <tr><td><tt>h
</tt></td><td>Hash function
</td></tr>
387 <tr><td><tt>hsize
</tt></td><td>Hash size
</td></tr>
388 </tbody></table></div>
392 <h3 class='title'
><a name='cupsArrayNext'
>cupsArrayNext()
</a></h3>
394 <p>Get the next element in the array.
399 <a href='#cups_array_t'
>cups_array_t
</a> * a);
402 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
403 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
405 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
406 </tbody></table></div>
408 <p>Next element or NULL
</p>
410 <h3 class='title'
><a name='cupsArrayPrev'
>cupsArrayPrev()
</a></h3>
412 <p>Get the previous element in the array.
417 <a href='#cups_array_t'
>cups_array_t
</a> * a);
420 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
421 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
423 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
424 </tbody></table></div>
426 <p>Previous element or NULL
</p>
428 <h3 class='title'
><a name='cupsArrayRemove'
>cupsArrayRemove()
</a></h3>
430 <p>Remove an element from the array.
435 <a href='#cups_array_t'
>cups_array_t
</a> * a,
439 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
440 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
442 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
443 <tr><td><tt>e
</tt></td><td>Element
</td></tr>
444 </tbody></table></div>
446 <p>1 on success,
0 on failure
</p>
448 <h3 class='title'
><a name='cupsArrayRestore'
>cupsArrayRestore()
</a></h3>
450 <p>Reset the current element to the last cupsArraySave.
455 <a href='#cups_array_t'
>cups_array_t
</a> * a);
458 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
459 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
461 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
462 </tbody></table></div>
464 <p>New current element
</p>
466 <h3 class='title'
><a name='cupsArraySave'
>cupsArraySave()
</a></h3>
468 <p>Mark the current element for a later cupsArrayRestore.
469 <p>The save/restore stack is guaranteed to be at least
32 elements deep.
474 <a href='#cups_array_t'
>cups_array_t
</a> * a);
477 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
478 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
480 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
481 </tbody></table></div>
483 <p>1 on success,
0 on failure
</p>
485 <h3 class='title'
><a name='cupsArrayUserData'
>cupsArrayUserData()
</a></h3>
487 <p>Return the user data for an array.
492 <a href='#cups_array_t'
>cups_array_t
</a> * a);
495 <div class='table'
><table align='center' border='
1' width='
80%' cellpadding='
5' cellspacing='
0' summary='Arguments'
>
496 <thead><tr><th>Name
</th><th>Description
</th></tr></thead>
498 <tr><td><tt>a
</tt></td><td>Array
</td></tr>
499 </tbody></table></div>
503 <h2 class='title'
><a name='TYPES'
>Types
</a></h2>
505 <li><a href='#cups_ahash_func_t'
><tt>cups_ahash_func_t
</tt></a> </li>
506 <li><a href='#cups_array_func_t'
><tt>cups_array_func_t
</tt></a> </li>
507 <li><a href='#cups_array_t'
><tt>cups_array_t
</tt></a> </li>
510 <h3 class='title'
><a name='cups_ahash_func_t'
>cups_ahash_func_t
</a></h3>
512 <p>Array hash function
515 typedef int (*cups_ahash_func_t)(void *element, void *data);
518 <h3 class='title'
><a name='cups_array_func_t'
>cups_array_func_t
</a></h3>
520 <p>Array comparison function
523 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
526 <h3 class='title'
><a name='cups_array_t'
>cups_array_t
</a></h3>
531 typedef struct _cups_array_s cups_array_t;