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.6">
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;
37 border: dotted thin #999999;
42 PRE.command EM, PRE.example EM {
43 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
47 font-family: monaco, courier, monospace;
58 border: solid thin #999999;
69 -moz-border-radius: 10px;
74 text-decoration: none;
77 A:link:hover, A:visited:hover, A:active {
78 text-decoration: underline;
85 TR.data, TD.data, TR.data TD {
88 border-bottom: solid 1pt #999999;
92 border-bottom: solid 1pt #999999;
99 border: solid thin #999999;
100 border-collapse: collapse;
116 border: solid thin #cccccc;
123 border-bottom: solid thin #999999;
132 caption-side: bottom;
156 border: thin solid black;
164 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
170 border-bottom: solid 2pt #000000;
173 DIV.indent, TABLE.indent {
181 border-collapse: collapse;
184 TABLE.indent TD, TABLE.indent TH {
189 border-collapse: collapse;
197 border-bottom: solid thin #cccccc;
202 vertical-align: bottom;
211 border-bottom: solid thin #eeeeee;
216 TABLE.list TR:nth-child(even) {
220 TABLE.list TR:nth-child(odd) {
239 font-family: monaco, courier, monospace;
243 border: solid thin #999999;
244 border-collapse: collapse;
249 DIV.summary TABLE TD, DIV.summary TABLE TH {
250 border: solid thin #999999;
256 DIV.summary TABLE THEAD TH {
260 /* API documentation styles... */
267 div.body h3, div.body h4, div.body h5 {
268 margin-bottom: 0.5em;
271 .class, .enumeration, .function, .struct, .typedef, .union {
272 border-bottom: solid thin #999999;
279 code, p.code, pre, ul.code li {
280 font-family: monaco, courier, monospace;
283 ul.code, ul.contents, ul.subcontents {
284 list-style-type: none;
294 ul.contents li ul.code, ul.contents li ul.subcontents {
307 margin-bottom: 0.5em;
310 /* This is just for the HTML files generated with the framedhelp target */
313 border: solid thin black;
322 div.contents ul.contents {
325 div.contents ul.subcontents li {
334 "$Id: api-array.header 8087 2008-10-27 21:37:05Z mike $"
336 Array API header for the Common UNIX Printing System (CUPS).
338 Copyright 2008 by Apple Inc.
340 These coded instructions, statements, and computer programs are the
341 property of Apple Inc. and are protected by Federal copyright
342 law. Distribution and use rights are outlined in the file "LICENSE.txt"
343 which should have been included with this file. If this file is
344 file is missing or damaged, see the license at "http://www.cups.org/".
347 <div class='summary'
><table summary='General Information'
>
351 <th>cups/array.h
</th>
361 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
365 <h2 class=
"title">Contents
</h2>
366 <ul class=
"contents">
367 <ul class=
"subcontents">
368 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
369 <li><a href=
"#MANAGING_ARRAYS">Managing Arrays
</a></li>
370 <li><a href=
"#FINDING_AND_ENUMERATING">Finding and Enumerating Elements
</a></li>
372 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
373 <li><a href=
"#cupsArrayAdd" title=
"Add an element to the array.">cupsArrayAdd
</a></li>
374 <li><a href=
"#cupsArrayClear" title=
"Clear the array.">cupsArrayClear
</a></li>
375 <li><a href=
"#cupsArrayCount" title=
"Get the number of elements in the array.">cupsArrayCount
</a></li>
376 <li><a href=
"#cupsArrayCurrent" title=
"Return the current element in the array.">cupsArrayCurrent
</a></li>
377 <li><a href=
"#cupsArrayDelete" title=
"Free all memory used by the array.">cupsArrayDelete
</a></li>
378 <li><a href=
"#cupsArrayDup" title=
"Duplicate the array.">cupsArrayDup
</a></li>
379 <li><a href=
"#cupsArrayFind" title=
"Find an element in the array.">cupsArrayFind
</a></li>
380 <li><a href=
"#cupsArrayFirst" title=
"Get the first element in the array.">cupsArrayFirst
</a></li>
381 <li><a href=
"#cupsArrayGetIndex" title=
"Get the index of the current element.">cupsArrayGetIndex
</a></li>
382 <li><a href=
"#cupsArrayGetInsert" title=
"Get the index of the last inserted element.">cupsArrayGetInsert
</a></li>
383 <li><a href=
"#cupsArrayIndex" title=
"Get the N-th element in the array.">cupsArrayIndex
</a></li>
384 <li><a href=
"#cupsArrayInsert" title=
"Insert an element in the array.">cupsArrayInsert
</a></li>
385 <li><a href=
"#cupsArrayLast" title=
"Get the last element in the array.">cupsArrayLast
</a></li>
386 <li><a href=
"#cupsArrayNew" title=
"Create a new array.">cupsArrayNew
</a></li>
387 <li><a href=
"#cupsArrayNew2" title=
"Create a new array with hash.">cupsArrayNew2
</a></li>
388 <li><a href=
"#cupsArrayNext" title=
"Get the next element in the array.">cupsArrayNext
</a></li>
389 <li><a href=
"#cupsArrayPrev" title=
"Get the previous element in the array.">cupsArrayPrev
</a></li>
390 <li><a href=
"#cupsArrayRemove" title=
"Remove an element from the array.">cupsArrayRemove
</a></li>
391 <li><a href=
"#cupsArrayRestore" title=
"Reset the current element to the last cupsArraySave.">cupsArrayRestore
</a></li>
392 <li><a href=
"#cupsArraySave" title=
"Mark the current element for a later cupsArrayRestore.">cupsArraySave
</a></li>
393 <li><a href=
"#cupsArrayUserData" title=
"Return the user data for an array.">cupsArrayUserData
</a></li>
395 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
396 <li><a href=
"#cups_ahash_func_t" title=
"Array hash function">cups_ahash_func_t
</a></li>
397 <li><a href=
"#cups_array_func_t" title=
"Array comparison function">cups_array_func_t
</a></li>
398 <li><a href=
"#cups_array_t" title=
"CUPS array type">cups_array_t
</a></li>
401 "$Id: api-array.shtml 7616 2008-05-28 00:34:13Z mike $"
403 Array API introduction for the Common UNIX Printing System (CUPS).
405 Copyright 2007-2008 by Apple Inc.
406 Copyright 1997-2006 by Easy Software Products, all rights reserved.
408 These coded instructions, statements, and computer programs are the
409 property of Apple Inc. and are protected by Federal copyright
410 law. Distribution and use rights are outlined in the file "LICENSE.txt"
411 which should have been included with this file. If this file is
412 file is missing or damaged, see the license at "http://www.cups.org/".
415 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
417 <p>The CUPS array API provides a high-performance generic array container.
418 The contents of the array container can be sorted and the container itself is
419 designed for optimal speed and memory usage under a wide variety of conditions.
420 Sorted arrays use a binary search algorithm from the last found or inserted
421 element to quickly find matching elements in the array. Arrays created with the
422 optional hash function can often find elements with a single lookup. The
423 <a href='#cups_array_t'
><code>cups_array_t
</code></a> type is used when
424 referring to a CUPS array.
</p>
426 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
427 functions use the array API to efficiently manage large lists of
430 <h3><a name='MANAGING_ARRAYS'
>Managing Arrays
</a></h3>
432 <p>Arrays are created using either the
433 <a href='#cupsArrayNew'
><code>cupsArrayNew
</code></a> or
434 <a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> functions. The
435 first function creates a new array with the specified callback function
436 and user data pointer:
</p>
438 <pre class='example'
>
439 #include
<cups/array.h
>
441 static int compare_func(void *first, void *second, void *user_data);
444 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>(compare_func, user_data);
447 <p>The comparison function (type
448 <a href=
"#cups_arrayfunc_t"><code>cups_arrayfunc_t
</code></a>) is called
449 whenever an element is added to the array and can be
<code>NULL
</code> to
450 create an unsorted array. The function returns -
1 if the first element should
451 come before the second,
0 if the first and second elements should have the same
452 ordering, and
1 if the first element should come after the second.
</p>
454 <p>The
"user_data" pointer is passed to your comparison function. Pass
455 <code>NULL
</code> if you do not need to associate the elements in your array
456 with additional information.
</p>
458 <p>The
<a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> function adds
459 two more arguments to support hashed lookups, which can potentially provide
460 instantaneous (
"O(1)") lookups in your array:
</p>
462 <pre class='example'
>
463 #include
<cups/array.h
>
465 #define HASH_SIZE
512 /* Size of hash table */
467 static int compare_func(void *first, void *second, void *user_data);
468 static int hash_func(void *element, void *user_data);
471 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew2'
>cupsArrayNew2
</a>(compare_func, user_data, hash_func, HASH_SIZE);
474 <p>The hash function (type
475 <a href=
"#cups_ahash_func_t"><code>cups_ahash_func_t
</code></a>) should return a
476 number from
0 to (hash_size-
1) that (hopefully) uniquely identifies the
477 element and is called whenever you look up an element in the array with
478 <a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a>. The hash size is
479 only limited by available memory, but generally should not be larger than
480 16384 to realize any performance improvement.
</p>
482 <p>Once you have created the array, you add elements using the
483 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a>
484 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> functions.
485 The first function adds an element to the array, adding the new element
486 after any elements that have the same order, while the second inserts the
487 element before others with the same order. For unsorted arrays,
488 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a> appends the element to
489 the end of the array while
490 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> inserts the
491 element at the beginning of the array. For example, the following code
492 creates a sorted array of character strings:
</p>
494 <pre class='example'
>
495 #include
<cups/array.h
>
497 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
498 <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);
500 /* Add four strings to the array */
501 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
502 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
503 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
504 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
507 <p>Elements are removed using the
508 <a href='#cupsArrayRemove'
><code>cupsArrayRemove
</code></a> function, for
511 <pre class='example'
>
512 #include
<cups/array.h
>
514 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
515 <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);
517 /* Add four strings to the array */
518 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
519 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
520 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
521 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
523 /* Remove
"Red Fish" */
524 <a href='#cupsArrayRemove'
>cupsArrayRemove
</a>(array,
"Red Fish");
527 <p>Finally, you free the memory used by the array using the
528 <a href='#cupsArrayDelete'
><code>cupsArrayDelete
</code></a> function. All
529 of the memory for the array and hash table (if any) is freed, however
<em>CUPS
530 does not free the elements
</em> - if necessary, you must allocate and free the
531 elements yourself.
</p>
533 <h3><a name='FINDING_AND_ENUMERATING'
>Finding and Enumerating Elements
</a></h3>
535 <p>CUPS provides several functions to find and enumerate elements in an
536 array. Each one sets or updates a
"current index" into the array, such that
537 future lookups will start where the last one left off:
</p>
540 <dt><a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a></dt>
541 <dd>Returns the first matching element.
</dd>
542 <dt><a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a></dt>
543 <dd>Returns the first element in the array.
</dd>
544 <dt><a href='#cupsArrayIndex'
><code>cupsArrayIndex
</code></a></dt>
545 <dd>Returns the Nth element in the array, starting at
0.
</dd>
546 <dt><a href='#cupsArrayLast'
><code>cupsArrayLast
</code></a></dt>
547 <dd>Returns the last element in the array.
</dd>
548 <dt><a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a></dt>
549 <dd>Returns the next element in the array.
</dd>
550 <dt><a href='#cupsArrayPrev'
><code>cupsArrayPrev
</code></a></dt>
551 <dd>Returns the previous element in the array.
</dd>
554 <p>Each of these functions returns
<code>NULL
</code> when there is no
555 corresponding element. For example, a simple
<code>for
</code> loop using the
556 <a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a> and
557 <a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a> functions will
558 enumerate all of the strings in our previous example:
</p>
560 <pre class='example'
>
561 #include
<cups/array.h
>
563 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
564 <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);
566 /* Add four strings to the array */
567 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
568 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
569 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
570 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
572 /* Show all of the strings in the array */
574 for (s = (char *)
<a href='#cupsArrayFirst'
>cupsArrayFirst
</a>(array); s != NULL; s = (char *)
<a href='#cupsArrayNext'
>cupsArrayNext
</a>(array))
577 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
578 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayAdd">cupsArrayAdd
</a></h3>
579 <p class=
"description">Add an element to the array.
</p>
581 int cupsArrayAdd (
<br>
582 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
583 void *e
<br>
585 <h4 class=
"parameters">Parameters
</h4>
588 <dd class=
"description">Array
</dd>
590 <dd class=
"description">Element
</dd>
592 <h4 class=
"returnvalue">Return Value
</h4>
593 <p class=
"description">1 on success,
0 on failure
</p>
594 <h4 class=
"discussion">Discussion
</h4>
595 <p class=
"discussion">When adding an element to a sorted array, non-unique elements are
596 appended at the end of the run of identical elements. For unsorted arrays,
597 the element is appended to the end of the array.
600 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayClear">cupsArrayClear
</a></h3>
601 <p class=
"description">Clear the array.
</p>
603 void cupsArrayClear (
<br>
604 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
606 <h4 class=
"parameters">Parameters
</h4>
609 <dd class=
"description">Array
</dd>
611 <h4 class=
"discussion">Discussion
</h4>
612 <p class=
"discussion">This function is equivalent to removing all elements in the array.
613 The caller is responsible for freeing the memory used by the
617 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayCount">cupsArrayCount
</a></h3>
618 <p class=
"description">Get the number of elements in the array.
</p>
620 int cupsArrayCount (
<br>
621 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
623 <h4 class=
"parameters">Parameters
</h4>
626 <dd class=
"description">Array
</dd>
628 <h4 class=
"returnvalue">Return Value
</h4>
629 <p class=
"description">Number of elements
</p>
630 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayCurrent">cupsArrayCurrent
</a></h3>
631 <p class=
"description">Return the current element in the array.
</p>
633 void *cupsArrayCurrent (
<br>
634 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
636 <h4 class=
"parameters">Parameters
</h4>
639 <dd class=
"description">Array
</dd>
641 <h4 class=
"returnvalue">Return Value
</h4>
642 <p class=
"description">Element
</p>
643 <h4 class=
"discussion">Discussion
</h4>
644 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
645 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
648 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayDelete">cupsArrayDelete
</a></h3>
649 <p class=
"description">Free all memory used by the array.
</p>
651 void cupsArrayDelete (
<br>
652 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
654 <h4 class=
"parameters">Parameters
</h4>
657 <dd class=
"description">Array
</dd>
659 <h4 class=
"discussion">Discussion
</h4>
660 <p class=
"discussion">The caller is responsible for freeing the memory used by the
664 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayDup">cupsArrayDup
</a></h3>
665 <p class=
"description">Duplicate the array.
</p>
667 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayDup (
<br>
668 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
670 <h4 class=
"parameters">Parameters
</h4>
673 <dd class=
"description">Array
</dd>
675 <h4 class=
"returnvalue">Return Value
</h4>
676 <p class=
"description">Duplicate array
</p>
677 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayFind">cupsArrayFind
</a></h3>
678 <p class=
"description">Find an element in the array.
</p>
680 void *cupsArrayFind (
<br>
681 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
682 void *e
<br>
684 <h4 class=
"parameters">Parameters
</h4>
687 <dd class=
"description">Array
</dd>
689 <dd class=
"description">Element
</dd>
691 <h4 class=
"returnvalue">Return Value
</h4>
692 <p class=
"description">Element found or
<code>NULL
</code></p>
693 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayFirst">cupsArrayFirst
</a></h3>
694 <p class=
"description">Get the first element in the array.
</p>
696 void *cupsArrayFirst (
<br>
697 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
699 <h4 class=
"parameters">Parameters
</h4>
702 <dd class=
"description">Array
</dd>
704 <h4 class=
"returnvalue">Return Value
</h4>
705 <p class=
"description">First element or
<code>NULL
</code> if the array is empty
</p>
706 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayGetIndex">cupsArrayGetIndex
</a></h3>
707 <p class=
"description">Get the index of the current element.
</p>
709 int cupsArrayGetIndex (
<br>
710 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
712 <h4 class=
"parameters">Parameters
</h4>
715 <dd class=
"description">Array
</dd>
717 <h4 class=
"returnvalue">Return Value
</h4>
718 <p class=
"description">Index of the current element, starting at
0</p>
719 <h4 class=
"discussion">Discussion
</h4>
720 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
721 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
724 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayGetInsert">cupsArrayGetInsert
</a></h3>
725 <p class=
"description">Get the index of the last inserted element.
</p>
727 int cupsArrayGetInsert (
<br>
728 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
730 <h4 class=
"parameters">Parameters
</h4>
733 <dd class=
"description">Array
</dd>
735 <h4 class=
"returnvalue">Return Value
</h4>
736 <p class=
"description">Index of the last inserted element, starting at
0</p>
737 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayIndex">cupsArrayIndex
</a></h3>
738 <p class=
"description">Get the N-th element in the array.
</p>
740 void *cupsArrayIndex (
<br>
741 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
742 int n
<br>
744 <h4 class=
"parameters">Parameters
</h4>
747 <dd class=
"description">Array
</dd>
749 <dd class=
"description">Index into array, starting at
0</dd>
751 <h4 class=
"returnvalue">Return Value
</h4>
752 <p class=
"description">N-th element or
<code>NULL
</code></p>
753 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayInsert">cupsArrayInsert
</a></h3>
754 <p class=
"description">Insert an element in the array.
</p>
756 int cupsArrayInsert (
<br>
757 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
758 void *e
<br>
760 <h4 class=
"parameters">Parameters
</h4>
763 <dd class=
"description">Array
</dd>
765 <dd class=
"description">Element
</dd>
767 <h4 class=
"returnvalue">Return Value
</h4>
768 <p class=
"description">0 on failure,
1 on success
</p>
769 <h4 class=
"discussion">Discussion
</h4>
770 <p class=
"discussion">When inserting an element in a sorted array, non-unique elements are
771 inserted at the beginning of the run of identical elements. For unsorted
772 arrays, the element is inserted at the beginning of the array.
775 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayLast">cupsArrayLast
</a></h3>
776 <p class=
"description">Get the last element in the array.
</p>
778 void *cupsArrayLast (
<br>
779 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
781 <h4 class=
"parameters">Parameters
</h4>
784 <dd class=
"description">Array
</dd>
786 <h4 class=
"returnvalue">Return Value
</h4>
787 <p class=
"description">Last element or
<code>NULL
</code> if the array is empty
</p>
788 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayNew">cupsArrayNew
</a></h3>
789 <p class=
"description">Create a new array.
</p>
791 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew (
<br>
792 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
793 void *d
<br>
795 <h4 class=
"parameters">Parameters
</h4>
798 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
800 <dd class=
"description">User data pointer or
<code>NULL
</code></dd>
802 <h4 class=
"returnvalue">Return Value
</h4>
803 <p class=
"description">Array
</p>
804 <h4 class=
"discussion">Discussion
</h4>
805 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
806 receives pointers to two elements and the user data pointer (
"d
") - the user
807 data pointer argument can safely be omitted when not required so functions
808 like
<code>strcmp
</code> can be used for sorted string arrays.
811 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayNew2">cupsArrayNew2
</a></h3>
812 <p class=
"description">Create a new array with hash.
</p>
814 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew2 (
<br>
815 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
816 void *d,
<br>
817 <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br>
818 int hsize
<br>
820 <h4 class=
"parameters">Parameters
</h4>
823 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
825 <dd class=
"description">User data or
<code>NULL
</code></dd>
827 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
829 <dd class=
"description">Hash size (
>=
0)
</dd>
831 <h4 class=
"returnvalue">Return Value
</h4>
832 <p class=
"description">Array
</p>
833 <h4 class=
"discussion">Discussion
</h4>
834 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
835 receives pointers to two elements and the user data pointer (
"d
") - the user
836 data pointer argument can safely be omitted when not required so functions
837 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
839 The hash function (
"h
") is used to implement cached lookups with the
840 specified hash size (
"hsize
").
843 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayNext">cupsArrayNext
</a></h3>
844 <p class=
"description">Get the next element in the array.
</p>
846 void *cupsArrayNext (
<br>
847 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
849 <h4 class=
"parameters">Parameters
</h4>
852 <dd class=
"description">Array
</dd>
854 <h4 class=
"returnvalue">Return Value
</h4>
855 <p class=
"description">Next element or
<code>NULL
</code></p>
856 <h4 class=
"discussion">Discussion
</h4>
857 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) +
1)
".
<br>
859 The next element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
860 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
861 to set the current element.
864 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayPrev">cupsArrayPrev
</a></h3>
865 <p class=
"description">Get the previous element in the array.
</p>
867 void *cupsArrayPrev (
<br>
868 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
870 <h4 class=
"parameters">Parameters
</h4>
873 <dd class=
"description">Array
</dd>
875 <h4 class=
"returnvalue">Return Value
</h4>
876 <p class=
"description">Previous element or
<code>NULL
</code></p>
877 <h4 class=
"discussion">Discussion
</h4>
878 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) -
1)
".
<br>
880 The previous element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
881 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
882 to set the current element.
885 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayRemove">cupsArrayRemove
</a></h3>
886 <p class=
"description">Remove an element from the array.
</p>
888 int cupsArrayRemove (
<br>
889 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
890 void *e
<br>
892 <h4 class=
"parameters">Parameters
</h4>
895 <dd class=
"description">Array
</dd>
897 <dd class=
"description">Element
</dd>
899 <h4 class=
"returnvalue">Return Value
</h4>
900 <p class=
"description">1 on success,
0 on failure
</p>
901 <h4 class=
"discussion">Discussion
</h4>
902 <p class=
"discussion">If more than one element matches
"e
", only the first matching element is
905 The caller is responsible for freeing the memory used by the
909 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayRestore">cupsArrayRestore
</a></h3>
910 <p class=
"description">Reset the current element to the last
<a href=
"#cupsArraySave"><code>cupsArraySave
</code></a>.
</p>
912 void *cupsArrayRestore (
<br>
913 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
915 <h4 class=
"parameters">Parameters
</h4>
918 <dd class=
"description">Array
</dd>
920 <h4 class=
"returnvalue">Return Value
</h4>
921 <p class=
"description">New current element
</p>
922 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArraySave">cupsArraySave
</a></h3>
923 <p class=
"description">Mark the current element for a later
<a href=
"#cupsArrayRestore"><code>cupsArrayRestore
</code></a>.
</p>
925 int cupsArraySave (
<br>
926 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
928 <h4 class=
"parameters">Parameters
</h4>
931 <dd class=
"description">Array
</dd>
933 <h4 class=
"returnvalue">Return Value
</h4>
934 <p class=
"description">1 on success,
0 on failure
</p>
935 <h4 class=
"discussion">Discussion
</h4>
936 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
937 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
938 to set the current element.
<br>
940 The save/restore stack is guaranteed to be at least
32 elements deep.
943 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayUserData">cupsArrayUserData
</a></h3>
944 <p class=
"description">Return the user data for an array.
</p>
946 void *cupsArrayUserData (
<br>
947 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
949 <h4 class=
"parameters">Parameters
</h4>
952 <dd class=
"description">Array
</dd>
954 <h4 class=
"returnvalue">Return Value
</h4>
955 <p class=
"description">User data
</p>
956 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
957 <h3 class=
"typedef"><a name=
"cups_ahash_func_t">cups_ahash_func_t
</a></h3>
958 <p class=
"description">Array hash function
</p>
960 typedef int (*cups_ahash_func_t)(void *element, void *data);
962 <h3 class=
"typedef"><a name=
"cups_array_func_t">cups_array_func_t
</a></h3>
963 <p class=
"description">Array comparison function
</p>
965 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
967 <h3 class=
"typedef"><a name=
"cups_array_t">cups_array_t
</a></h3>
968 <p class=
"description">CUPS array type
</p>
970 typedef struct _cups_array_s cups_array_t;