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.5">
8 <style type=
"text/css"><!--
10 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
13 H1, H2, H3, H4, H5, H6, P, TD, TH {
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
18 font-family: monaco, courier, monospace;
23 font-family: monaco, courier, monospace;
32 border: dotted thin #999999;
37 PRE.command EM, PRE.example EM {
38 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
42 font-family: monaco, courier, monospace;
53 border: solid thin #999999;
59 text-decoration: none;
62 A:link:hover, A:visited:hover, A:active {
63 text-decoration: underline;
71 border: solid thin #999999;
72 border-collapse: collapse;
88 border: solid thin #cccccc;
95 border-bottom: solid thin #999999;
104 caption-side: bottom;
124 border: thin solid #000000;
132 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
138 border-bottom: solid 2pt #000000;
156 font-family: monaco, courier, monospace;
165 border: solid thin #999999;
166 border-collapse: collapse;
171 DIV.summary TABLE TD, DIV.summary TABLE TH {
172 border: solid thin #999999;
178 DIV.summary TABLE THEAD TH {
182 /* API documentation styles... */
189 div.body h3, div.body h4, div.body h5 {
190 margin-bottom: 0.5em;
193 .class, .enumeration, .function, .struct, .typedef, .union {
194 border-bottom: solid thin #999999;
201 code, p.code, pre, ul.code li {
202 font-family: monaco, courier, monospace;
205 ul.code, ul.contents, ul.subcontents {
206 list-style-type: none;
216 ul.contents li ul.code, ul.contents li ul.subcontents {
229 margin-bottom: 0.5em;
232 /* This is just for the HTML files generated with the framedhelp target */
235 border: solid thin black;
244 div.contents ul.contents {
247 div.contents ul.subcontents li {
256 "$Id: api-array.header 7266 2008-01-29 02:15:29Z mike $"
258 Array API header for the Common UNIX Printing System (CUPS).
260 Copyright 2008 by Apple Inc.
262 These coded instructions, statements, and computer programs are the
263 property of Apple Inc. and are protected by Federal copyright
264 law. Distribution and use rights are outlined in the file "LICENSE.txt"
265 which should have been included with this file. If this file is
266 file is missing or damaged, see the license at "http://www.cups.org/".
269 <h1 class=
"title">Array API
</h1>
271 <div class='summary'
><table summary='General Information'
>
275 <th>cups/array.h
</th>
285 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
289 <h2 class=
"title">Contents
</h2>
290 <ul class=
"contents">
292 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
293 <li><a href=
"#MANAGING_ARRAYS">Managing Arrays
</a></li>
294 <li><a href=
"#FINDING_AND_ENUMERATING">Finding and Enumerating Elements
</a></li>
296 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
297 <li><a href=
"#cupsArrayAdd" title=
"Add an element to the array.">cupsArrayAdd
</a></li>
298 <li><a href=
"#cupsArrayClear" title=
"Clear the array.">cupsArrayClear
</a></li>
299 <li><a href=
"#cupsArrayCount" title=
"Get the number of elements in the array.">cupsArrayCount
</a></li>
300 <li><a href=
"#cupsArrayCurrent" title=
"Return the current element in the array.">cupsArrayCurrent
</a></li>
301 <li><a href=
"#cupsArrayDelete" title=
"Free all memory used by the array.">cupsArrayDelete
</a></li>
302 <li><a href=
"#cupsArrayDup" title=
"Duplicate the array.">cupsArrayDup
</a></li>
303 <li><a href=
"#cupsArrayFind" title=
"Find an element in the array.">cupsArrayFind
</a></li>
304 <li><a href=
"#cupsArrayFirst" title=
"Get the first element in the array.">cupsArrayFirst
</a></li>
305 <li><a href=
"#cupsArrayGetIndex" title=
"Get the index of the current element.">cupsArrayGetIndex
</a></li>
306 <li><a href=
"#cupsArrayGetInsert" title=
"Get the index of the last inserted element.">cupsArrayGetInsert
</a></li>
307 <li><a href=
"#cupsArrayIndex" title=
"Get the N-th element in the array.">cupsArrayIndex
</a></li>
308 <li><a href=
"#cupsArrayInsert" title=
"Insert an element in the array.">cupsArrayInsert
</a></li>
309 <li><a href=
"#cupsArrayLast" title=
"Get the last element in the array.">cupsArrayLast
</a></li>
310 <li><a href=
"#cupsArrayNew" title=
"Create a new array.">cupsArrayNew
</a></li>
311 <li><a href=
"#cupsArrayNew2" title=
"Create a new array with hash.">cupsArrayNew2
</a></li>
312 <li><a href=
"#cupsArrayNext" title=
"Get the next element in the array.">cupsArrayNext
</a></li>
313 <li><a href=
"#cupsArrayPrev" title=
"Get the previous element in the array.">cupsArrayPrev
</a></li>
314 <li><a href=
"#cupsArrayRemove" title=
"Remove an element from the array.">cupsArrayRemove
</a></li>
315 <li><a href=
"#cupsArrayRestore" title=
"Reset the current element to the last <a href="#cupsArraySave
"><code>cupsArraySave</code></a>.">cupsArrayRestore
</a></li>
316 <li><a href=
"#cupsArraySave" title=
"Mark the current element for a later <a href="#cupsArrayRestore
"><code>cupsArrayRestore</code></a>.">cupsArraySave
</a></li>
317 <li><a href=
"#cupsArrayUserData" title=
"Return the user data for an array.">cupsArrayUserData
</a></li>
319 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
320 <li><a href=
"#cups_ahash_func_t" title=
"Array hash function">cups_ahash_func_t
</a></li>
321 <li><a href=
"#cups_array_func_t" title=
"Array comparison function">cups_array_func_t
</a></li>
322 <li><a href=
"#cups_array_t" title=
"CUPS array type">cups_array_t
</a></li>
326 "$Id: api-array.shtml 7616 2008-05-28 00:34:13Z mike $"
328 Array API introduction for the Common UNIX Printing System (CUPS).
330 Copyright 2007-2008 by Apple Inc.
331 Copyright 1997-2006 by Easy Software Products, all rights reserved.
333 These coded instructions, statements, and computer programs are the
334 property of Apple Inc. and are protected by Federal copyright
335 law. Distribution and use rights are outlined in the file "LICENSE.txt"
336 which should have been included with this file. If this file is
337 file is missing or damaged, see the license at "http://www.cups.org/".
340 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
342 <p>The CUPS array API provides a high-performance generic array container.
343 The contents of the array container can be sorted and the container itself is
344 designed for optimal speed and memory usage under a wide variety of conditions.
345 Sorted arrays use a binary search algorithm from the last found or inserted
346 element to quickly find matching elements in the array. Arrays created with the
347 optional hash function can often find elements with a single lookup. The
348 <a href='#cups_array_t'
><code>cups_array_t
</code></a> type is used when
349 referring to a CUPS array.
</p>
351 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
352 functions use the array API to efficiently manage large lists of
355 <h3><a name='MANAGING_ARRAYS'
>Managing Arrays
</a></h3>
357 <p>Arrays are created using either the
358 <a href='#cupsArrayNew'
><code>cupsArrayNew
</code></a> or
359 <a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> functions. The
360 first function creates a new array with the specified callback function
361 and user data pointer:
</p>
363 <pre class='example'
>
364 #include
<cups/array.h
>
366 static int compare_func(void *first, void *second, void *user_data);
369 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>(compare_func, user_data);
372 <p>The comparison function (type
373 <a href=
"#cups_arrayfunc_t"><code>cups_arrayfunc_t
</code></a>) is called
374 whenever an element is added to the array and can be
<code>NULL
</code> to
375 create an unsorted array. The function returns -
1 if the first element should
376 come before the second,
0 if the first and second elements should have the same
377 ordering, and
1 if the first element should come after the second.
</p>
379 <p>The
"user_data" pointer is passed to your comparison function. Pass
380 <code>NULL
</code> if you do not need to associate the elements in your array
381 with additional information.
</p>
383 <p>The
<a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> function adds
384 two more arguments to support hashed lookups, which can potentially provide
385 instantaneous (
"O(1)") lookups in your array:
</p>
387 <pre class='example'
>
388 #include
<cups/array.h
>
390 #define HASH_SIZE
512 /* Size of hash table */
392 static int compare_func(void *first, void *second, void *user_data);
393 static int hash_func(void *element, void *user_data);
396 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew2'
>cupsArrayNew2
</a>(compare_func, user_data, hash_func, HASH_SIZE);
399 <p>The hash function (type
400 <a href=
"#cups_ahash_func_t"><code>cups_ahash_func_t
</code></a>) should return a
401 number from
0 to (hash_size-
1) that (hopefully) uniquely identifies the
402 element and is called whenever you look up an element in the array with
403 <a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a>. The hash size is
404 only limited by available memory, but generally should not be larger than
405 16384 to realize any performance improvement.
</p>
407 <p>Once you have created the array, you add elements using the
408 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a>
409 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> functions.
410 The first function adds an element to the array, adding the new element
411 after any elements that have the same order, while the second inserts the
412 element before others with the same order. For unsorted arrays,
413 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a> appends the element to
414 the end of the array while
415 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> inserts the
416 element at the beginning of the array. For example, the following code
417 creates a sorted array of character strings:
</p>
419 <pre class='example'
>
420 #include
<cups/array.h
>
422 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
423 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>((
<a href='#cups_array_func_t'
>cups_array_func_t
</a>)strcmp, NULL);
425 /* Add four strings to the array */
426 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
427 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
428 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
429 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
432 <p>Elements are removed using the
433 <a href='#cupsArrayRemove'
><code>cupsArrayRemove
</code></a> function, for
436 <pre class='example'
>
437 #include
<cups/array.h
>
439 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
440 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>((
<a href='#cups_array_func_t'
>cups_array_func_t
</a>)strcmp, NULL);
442 /* Add four strings to the array */
443 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
444 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
445 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
446 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
448 /* Remove
"Red Fish" */
449 <a href='#cupsArrayRemove'
>cupsArrayRemove
</a>(array,
"Red Fish");
452 <p>Finally, you free the memory used by the array using the
453 <a href='#cupsArrayDelete'
><code>cupsArrayDelete
</code></a> function. All
454 of the memory for the array and hash table (if any) is freed, however
<em>CUPS
455 does not free the elements
</em> - if necessary, you must allocate and free the
456 elements yourself.
</p>
458 <h3><a name='FINDING_AND_ENUMERATING'
>Finding and Enumerating Elements
</a></h3>
460 <p>CUPS provides several functions to find and enumerate elements in an
461 array. Each one sets or updates a
"current index" into the array, such that
462 future lookups will start where the last one left off:
</p>
465 <dt><a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a></dt>
466 <dd>Returns the first matching element.
</dd>
467 <dt><a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a></dt>
468 <dd>Returns the first element in the array.
</dd>
469 <dt><a href='#cupsArrayIndex'
><code>cupsArrayIndex
</code></a></dt>
470 <dd>Returns the Nth element in the array, starting at
0.
</dd>
471 <dt><a href='#cupsArrayLast'
><code>cupsArrayLast
</code></a></dt>
472 <dd>Returns the last element in the array.
</dd>
473 <dt><a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a></dt>
474 <dd>Returns the next element in the array.
</dd>
475 <dt><a href='#cupsArrayPrev'
><code>cupsArrayPrev
</code></a></dt>
476 <dd>Returns the previous element in the array.
</dd>
479 <p>Each of these functions returns
<code>NULL
</code> when there is no
480 corresponding element. For example, a simple
<code>for
</code> loop using the
481 <a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a> and
482 <a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a> functions will
483 enumerate all of the strings in our previous example:
</p>
485 <pre class='example'
>
486 #include
<cups/array.h
>
488 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
489 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>((
<a href='#cups_array_func_t'
>cups_array_func_t
</a>)strcmp, NULL);
491 /* Add four strings to the array */
492 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
493 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
494 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
495 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
497 /* Show all of the strings in the array */
499 for (s = (char *)
<a href='#cupsArrayFirst'
>cupsArrayFirst
</a>(array); s != NULL; s = (char *)
<a href='#cupsArrayNext'
>cupsArrayNext
</a>(array))
502 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
503 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayAdd">cupsArrayAdd
</a></h3>
504 <p class=
"description">Add an element to the array.
</p>
506 int cupsArrayAdd (
<br>
507 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
508 void *e
<br>
510 <h4 class=
"parameters">Parameters
</h4>
513 <dd class=
"description">Array
</dd>
515 <dd class=
"description">Element
</dd>
517 <h4 class=
"returnvalue">Return Value
</h4>
518 <p class=
"description">1 on success,
0 on failure
</p>
519 <h4 class=
"discussion">Discussion
</h4>
520 <p class=
"discussion">When adding an element to a sorted array, non-unique elements are
521 appended at the end of the run of identical elements. For unsorted arrays,
522 the element is appended to the end of the array.
525 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayClear">cupsArrayClear
</a></h3>
526 <p class=
"description">Clear the array.
</p>
528 void cupsArrayClear (
<br>
529 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
531 <h4 class=
"parameters">Parameters
</h4>
534 <dd class=
"description">Array
</dd>
536 <h4 class=
"discussion">Discussion
</h4>
537 <p class=
"discussion">This function is equivalent to removing all elements in the array.
538 The caller is responsible for freeing the memory used by the
542 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayCount">cupsArrayCount
</a></h3>
543 <p class=
"description">Get the number of elements in the array.
</p>
545 int cupsArrayCount (
<br>
546 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
548 <h4 class=
"parameters">Parameters
</h4>
551 <dd class=
"description">Array
</dd>
553 <h4 class=
"returnvalue">Return Value
</h4>
554 <p class=
"description">Number of elements
</p>
555 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayCurrent">cupsArrayCurrent
</a></h3>
556 <p class=
"description">Return the current element in the array.
</p>
558 void *cupsArrayCurrent (
<br>
559 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
561 <h4 class=
"parameters">Parameters
</h4>
564 <dd class=
"description">Array
</dd>
566 <h4 class=
"returnvalue">Return Value
</h4>
567 <p class=
"description">Element
</p>
568 <h4 class=
"discussion">Discussion
</h4>
569 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
570 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
573 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayDelete">cupsArrayDelete
</a></h3>
574 <p class=
"description">Free all memory used by the array.
</p>
576 void cupsArrayDelete (
<br>
577 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
579 <h4 class=
"parameters">Parameters
</h4>
582 <dd class=
"description">Array
</dd>
584 <h4 class=
"discussion">Discussion
</h4>
585 <p class=
"discussion">The caller is responsible for freeing the memory used by the
589 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayDup">cupsArrayDup
</a></h3>
590 <p class=
"description">Duplicate the array.
</p>
592 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayDup (
<br>
593 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
595 <h4 class=
"parameters">Parameters
</h4>
598 <dd class=
"description">Array
</dd>
600 <h4 class=
"returnvalue">Return Value
</h4>
601 <p class=
"description">Duplicate array
</p>
602 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayFind">cupsArrayFind
</a></h3>
603 <p class=
"description">Find an element in the array.
</p>
605 void *cupsArrayFind (
<br>
606 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
607 void *e
<br>
609 <h4 class=
"parameters">Parameters
</h4>
612 <dd class=
"description">Array
</dd>
614 <dd class=
"description">Element
</dd>
616 <h4 class=
"returnvalue">Return Value
</h4>
617 <p class=
"description">Element found or
<code>NULL
</code></p>
618 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayFirst">cupsArrayFirst
</a></h3>
619 <p class=
"description">Get the first element in the array.
</p>
621 void *cupsArrayFirst (
<br>
622 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
624 <h4 class=
"parameters">Parameters
</h4>
627 <dd class=
"description">Array
</dd>
629 <h4 class=
"returnvalue">Return Value
</h4>
630 <p class=
"description">First element or
<code>NULL
</code> if the array is empty
</p>
631 <h3 class=
"function"><span class=
"info"> CUPS
1.3 </span><a name=
"cupsArrayGetIndex">cupsArrayGetIndex
</a></h3>
632 <p class=
"description">Get the index of the current element.
</p>
634 int cupsArrayGetIndex (
<br>
635 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
637 <h4 class=
"parameters">Parameters
</h4>
640 <dd class=
"description">Array
</dd>
642 <h4 class=
"returnvalue">Return Value
</h4>
643 <p class=
"description">Index of the current element, starting at
0</p>
644 <h4 class=
"discussion">Discussion
</h4>
645 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
646 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
649 <h3 class=
"function"><span class=
"info"> CUPS
1.3 </span><a name=
"cupsArrayGetInsert">cupsArrayGetInsert
</a></h3>
650 <p class=
"description">Get the index of the last inserted element.
</p>
652 int cupsArrayGetInsert (
<br>
653 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
655 <h4 class=
"parameters">Parameters
</h4>
658 <dd class=
"description">Array
</dd>
660 <h4 class=
"returnvalue">Return Value
</h4>
661 <p class=
"description">Index of the last inserted element, starting at
0</p>
662 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayIndex">cupsArrayIndex
</a></h3>
663 <p class=
"description">Get the N-th element in the array.
</p>
665 void *cupsArrayIndex (
<br>
666 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
667 int n
<br>
669 <h4 class=
"parameters">Parameters
</h4>
672 <dd class=
"description">Array
</dd>
674 <dd class=
"description">Index into array, starting at
0</dd>
676 <h4 class=
"returnvalue">Return Value
</h4>
677 <p class=
"description">N-th element or
<code>NULL
</code></p>
678 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayInsert">cupsArrayInsert
</a></h3>
679 <p class=
"description">Insert an element in the array.
</p>
681 int cupsArrayInsert (
<br>
682 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
683 void *e
<br>
685 <h4 class=
"parameters">Parameters
</h4>
688 <dd class=
"description">Array
</dd>
690 <dd class=
"description">Element
</dd>
692 <h4 class=
"returnvalue">Return Value
</h4>
693 <p class=
"description">0 on failure,
1 on success
</p>
694 <h4 class=
"discussion">Discussion
</h4>
695 <p class=
"discussion">When inserting an element in a sorted array, non-unique elements are
696 inserted at the beginning of the run of identical elements. For unsorted
697 arrays, the element is inserted at the beginning of the array.
700 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayLast">cupsArrayLast
</a></h3>
701 <p class=
"description">Get the last element in the array.
</p>
703 void *cupsArrayLast (
<br>
704 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
706 <h4 class=
"parameters">Parameters
</h4>
709 <dd class=
"description">Array
</dd>
711 <h4 class=
"returnvalue">Return Value
</h4>
712 <p class=
"description">Last element or
<code>NULL
</code> if the array is empty
</p>
713 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayNew">cupsArrayNew
</a></h3>
714 <p class=
"description">Create a new array.
</p>
716 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew (
<br>
717 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
718 void *d
<br>
720 <h4 class=
"parameters">Parameters
</h4>
723 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
725 <dd class=
"description">User data pointer or
<code>NULL
</code></dd>
727 <h4 class=
"returnvalue">Return Value
</h4>
728 <p class=
"description">Array
</p>
729 <h4 class=
"discussion">Discussion
</h4>
730 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
731 receives pointers to two elements and the user data pointer (
"d
") - the user
732 data pointer argument can safely be omitted when not required so functions
733 like
<code>strcmp
</code> can be used for sorted string arrays.
736 <h3 class=
"function"><span class=
"info"> CUPS
1.3 </span><a name=
"cupsArrayNew2">cupsArrayNew2
</a></h3>
737 <p class=
"description">Create a new array with hash.
</p>
739 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew2 (
<br>
740 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
741 void *d,
<br>
742 <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br>
743 int hsize
<br>
745 <h4 class=
"parameters">Parameters
</h4>
748 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
750 <dd class=
"description">User data or
<code>NULL
</code></dd>
752 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
754 <dd class=
"description">Hash size (
>=
0)
</dd>
756 <h4 class=
"returnvalue">Return Value
</h4>
757 <p class=
"description">Array
</p>
758 <h4 class=
"discussion">Discussion
</h4>
759 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
760 receives pointers to two elements and the user data pointer (
"d
") - the user
761 data pointer argument can safely be omitted when not required so functions
762 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
764 The hash function (
"h
") is used to implement cached lookups with the
765 specified hash size (
"hsize
").
768 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayNext">cupsArrayNext
</a></h3>
769 <p class=
"description">Get the next element in the array.
</p>
771 void *cupsArrayNext (
<br>
772 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
774 <h4 class=
"parameters">Parameters
</h4>
777 <dd class=
"description">Array
</dd>
779 <h4 class=
"returnvalue">Return Value
</h4>
780 <p class=
"description">Next element or
<code>NULL
</code></p>
781 <h4 class=
"discussion">Discussion
</h4>
782 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) +
1)
".
<br>
784 The next element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
785 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
786 to set the current element.
789 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayPrev">cupsArrayPrev
</a></h3>
790 <p class=
"description">Get the previous element in the array.
</p>
792 void *cupsArrayPrev (
<br>
793 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
795 <h4 class=
"parameters">Parameters
</h4>
798 <dd class=
"description">Array
</dd>
800 <h4 class=
"returnvalue">Return Value
</h4>
801 <p class=
"description">Previous element or
<code>NULL
</code></p>
802 <h4 class=
"discussion">Discussion
</h4>
803 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) -
1)
".
<br>
805 The previous element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
806 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
807 to set the current element.
810 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayRemove">cupsArrayRemove
</a></h3>
811 <p class=
"description">Remove an element from the array.
</p>
813 int cupsArrayRemove (
<br>
814 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
815 void *e
<br>
817 <h4 class=
"parameters">Parameters
</h4>
820 <dd class=
"description">Array
</dd>
822 <dd class=
"description">Element
</dd>
824 <h4 class=
"returnvalue">Return Value
</h4>
825 <p class=
"description">1 on success,
0 on failure
</p>
826 <h4 class=
"discussion">Discussion
</h4>
827 <p class=
"discussion">If more than one element matches
"e
", only the first matching element is
830 The caller is responsible for freeing the memory used by the
834 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayRestore">cupsArrayRestore
</a></h3>
835 <p class=
"description">Reset the current element to the last
<a href=
"#cupsArraySave"><code>cupsArraySave
</code></a>.
</p>
837 void *cupsArrayRestore (
<br>
838 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
840 <h4 class=
"parameters">Parameters
</h4>
843 <dd class=
"description">Array
</dd>
845 <h4 class=
"returnvalue">Return Value
</h4>
846 <p class=
"description">New current element
</p>
847 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArraySave">cupsArraySave
</a></h3>
848 <p class=
"description">Mark the current element for a later
<a href=
"#cupsArrayRestore"><code>cupsArrayRestore
</code></a>.
</p>
850 int cupsArraySave (
<br>
851 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
853 <h4 class=
"parameters">Parameters
</h4>
856 <dd class=
"description">Array
</dd>
858 <h4 class=
"returnvalue">Return Value
</h4>
859 <p class=
"description">1 on success,
0 on failure
</p>
860 <h4 class=
"discussion">Discussion
</h4>
861 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
862 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
863 to set the current element.
<br>
865 The save/restore stack is guaranteed to be at least
32 elements deep.
868 <h3 class=
"function"><span class=
"info"> CUPS
1.2 </span><a name=
"cupsArrayUserData">cupsArrayUserData
</a></h3>
869 <p class=
"description">Return the user data for an array.
</p>
871 void *cupsArrayUserData (
<br>
872 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
874 <h4 class=
"parameters">Parameters
</h4>
877 <dd class=
"description">Array
</dd>
879 <h4 class=
"returnvalue">Return Value
</h4>
880 <p class=
"description">User data
</p>
881 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
882 <h3 class=
"typedef"><a name=
"cups_ahash_func_t">cups_ahash_func_t
</a></h3>
883 <p class=
"description">Array hash function
</p>
885 typedef int (*cups_ahash_func_t)(void *element, void *data);
887 <h3 class=
"typedef"><a name=
"cups_array_func_t">cups_array_func_t
</a></h3>
888 <p class=
"description">Array comparison function
</p>
890 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
892 <h3 class=
"typedef"><a name=
"cups_array_t">cups_array_t
</a></h3>
893 <p class=
"description">CUPS array type
</p>
895 typedef struct _cups_array_s cups_array_t;