3 <!-- SECTION: Programming -->
5 <title>Array API
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8">
8 <meta name=
"creator" content=
"Mini-XML v2.11">
9 <meta name=
"author" content=
"Unknown">
10 <meta name=
"copyright" content=
"Unknown">
11 <style type=
"text/css"><!--
13 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
16 H1, H2, H3, H4, H5, H6, P, TD, TH {
17 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
21 font-family: monaco, courier, monospace;
26 font-family: monaco, courier, monospace;
30 border: dotted thin #7f7f7f;
58 border: dotted thin #999999;
63 PRE.command EM, PRE.example EM {
64 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
68 font-family: monaco, courier, monospace;
79 border: solid thin #999999;
90 -moz-border-radius: 10px;
95 text-decoration: none;
98 A:link:hover, A:visited:hover, A:active {
99 text-decoration: underline;
106 TR.data, TD.data, TR.data TD {
109 border-bottom: solid 1pt #999999;
113 border-bottom: solid 1pt #999999;
120 border: solid thin #999999;
121 border-collapse: collapse;
137 border: solid thin #cccccc;
144 border-bottom: solid thin #999999;
153 caption-side: bottom;
177 border: thin solid black;
185 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
194 border-bottom: solid 2pt #000000;
197 DIV.indent, TABLE.indent {
205 border-collapse: collapse;
208 TABLE.indent TD, TABLE.indent TH {
213 border-collapse: collapse;
221 border-bottom: solid thin #cccccc;
226 vertical-align: bottom;
235 border-bottom: solid thin #eeeeee;
240 TABLE.list TR:nth-child(even) {
244 TABLE.list TR:nth-child(odd) {
263 font-family: monaco, courier, monospace;
267 border: solid thin #999999;
268 border-collapse: collapse;
273 DIV.summary TABLE TD, DIV.summary TABLE TH {
274 border: solid thin #999999;
280 DIV.summary TABLE THEAD TH {
284 /* API documentation styles... */
291 div.body h3, div.body h4, div.body h5 {
292 margin-bottom: 0.5em;
295 .class, .enumeration, .function, .struct, .typedef, .union {
296 border-bottom: solid thin #999999;
303 code, p.code, pre, ul.code li {
304 font-family: monaco, courier, monospace;
307 ul.code, ul.contents, ul.subcontents {
308 list-style-type: none;
318 ul.contents li ul.code, ul.contents li ul.subcontents {
331 margin-bottom: 0.5em;
334 /* This is just for the HTML files generated with the framedhelp target */
337 border: solid thin black;
346 div.contents ul.contents {
349 div.contents ul.subcontents li {
357 Array API header for CUPS.
359 Copyright 2008-2011 by Apple Inc.
361 These coded instructions, statements, and computer programs are the
362 property of Apple Inc. and are protected by Federal copyright
363 law. Distribution and use rights are outlined in the file "LICENSE.txt"
364 which should have been included with this file. If this file is
365 file is missing or damaged, see the license at "http://www.cups.org/".
368 <h1 class='title'
>Array API
</h1>
370 <div class='summary'
><table summary='General Information'
>
374 <th>cups/array.h
</th>
384 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
388 <div class=
"contents">
389 <h2 class=
"title">Contents
</h2>
390 <ul class=
"contents">
391 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
392 <li><a href=
"#MANAGING_ARRAYS">Managing Arrays
</a></li>
393 <li><a href=
"#FINDING_AND_ENUMERATING">Finding and Enumerating Elements
</a></li>
395 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"subcontents">
396 <li><a href=
"#cupsArrayAdd">cupsArrayAdd
</a></li>
397 <li><a href=
"#cupsArrayClear">cupsArrayClear
</a></li>
398 <li><a href=
"#cupsArrayCount">cupsArrayCount
</a></li>
399 <li><a href=
"#cupsArrayCurrent">cupsArrayCurrent
</a></li>
400 <li><a href=
"#cupsArrayDelete">cupsArrayDelete
</a></li>
401 <li><a href=
"#cupsArrayDup">cupsArrayDup
</a></li>
402 <li><a href=
"#cupsArrayFind">cupsArrayFind
</a></li>
403 <li><a href=
"#cupsArrayFirst">cupsArrayFirst
</a></li>
404 <li><a href=
"#cupsArrayGetIndex">cupsArrayGetIndex
</a></li>
405 <li><a href=
"#cupsArrayGetInsert">cupsArrayGetInsert
</a></li>
406 <li><a href=
"#cupsArrayIndex">cupsArrayIndex
</a></li>
407 <li><a href=
"#cupsArrayInsert">cupsArrayInsert
</a></li>
408 <li><a href=
"#cupsArrayLast">cupsArrayLast
</a></li>
409 <li><a href=
"#cupsArrayNew">cupsArrayNew
</a></li>
410 <li><a href=
"#cupsArrayNew2">cupsArrayNew2
</a></li>
411 <li><a href=
"#cupsArrayNew3">cupsArrayNew3
</a></li>
412 <li><a href=
"#cupsArrayNext">cupsArrayNext
</a></li>
413 <li><a href=
"#cupsArrayPrev">cupsArrayPrev
</a></li>
414 <li><a href=
"#cupsArrayRemove">cupsArrayRemove
</a></li>
415 <li><a href=
"#cupsArrayRestore">cupsArrayRestore
</a></li>
416 <li><a href=
"#cupsArraySave">cupsArraySave
</a></li>
417 <li><a href=
"#cupsArrayUserData">cupsArrayUserData
</a></li>
419 <li><a href=
"#TYPES">Data Types
</a><ul class=
"subcontents">
420 <li><a href=
"#cups_acopy_func_t">cups_acopy_func_t
</a></li>
421 <li><a href=
"#cups_afree_func_t">cups_afree_func_t
</a></li>
422 <li><a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a></li>
423 <li><a href=
"#cups_array_func_t">cups_array_func_t
</a></li>
424 <li><a href=
"#cups_array_t">cups_array_t
</a></li>
430 Array API introduction for CUPS.
432 Copyright 2007-2011 by Apple Inc.
433 Copyright 1997-2006 by Easy Software Products, all rights reserved.
435 These coded instructions, statements, and computer programs are the
436 property of Apple Inc. and are protected by Federal copyright
437 law. Distribution and use rights are outlined in the file "LICENSE.txt"
438 which should have been included with this file. If this file is
439 file is missing or damaged, see the license at "http://www.cups.org/".
442 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
444 <p>The CUPS array API provides a high-performance generic array container.
445 The contents of the array container can be sorted and the container itself is
446 designed for optimal speed and memory usage under a wide variety of conditions.
447 Sorted arrays use a binary search algorithm from the last found or inserted
448 element to quickly find matching elements in the array. Arrays created with the
449 optional hash function can often find elements with a single lookup. The
450 <a href='#cups_array_t'
><code>cups_array_t
</code></a> type is used when
451 referring to a CUPS array.
</p>
453 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
454 functions use the array API to efficiently manage large lists of
457 <h3><a name='MANAGING_ARRAYS'
>Managing Arrays
</a></h3>
459 <p>Arrays are created using either the
460 <a href='#cupsArrayNew'
><code>cupsArrayNew
</code></a>,
461 <a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a>, or
462 <a href='#cupsArrayNew2'
><code>cupsArrayNew3
</code></a> functions. The
463 first function creates a new array with the specified callback function
464 and user data pointer:
</p>
466 <pre class='example'
>
467 #include
<cups/array.h
>
469 static int compare_func(void *first, void *second, void *user_data);
472 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>(compare_func, user_data);
475 <p>The comparison function (type
476 <a href=
"#cups_arrayfunc_t"><code>cups_arrayfunc_t
</code></a>) is called
477 whenever an element is added to the array and can be
<code>NULL
</code> to
478 create an unsorted array. The function returns -
1 if the first element should
479 come before the second,
0 if the first and second elements should have the same
480 ordering, and
1 if the first element should come after the second.
</p>
482 <p>The
"user_data" pointer is passed to your comparison function. Pass
483 <code>NULL
</code> if you do not need to associate the elements in your array
484 with additional information.
</p>
486 <p>The
<a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> function adds
487 two more arguments to support hashed lookups, which can potentially provide
488 instantaneous (
"O(1)") lookups in your array:
</p>
490 <pre class='example'
>
491 #include
<cups/array.h
>
493 #define HASH_SIZE
512 /* Size of hash table */
495 static int compare_func(void *first, void *second, void *user_data);
496 static int hash_func(void *element, void *user_data);
499 <a href='#cups_array_t'
>cups_array_t
</a> *hash_array =
<a href='#cupsArrayNew2'
>cupsArrayNew2
</a>(compare_func, user_data, hash_func, HASH_SIZE);
502 <p>The hash function (type
503 <a href=
"#cups_ahash_func_t"><code>cups_ahash_func_t
</code></a>) should return a
504 number from
0 to (hash_size-
1) that (hopefully) uniquely identifies the
505 element and is called whenever you look up an element in the array with
506 <a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a>. The hash size is
507 only limited by available memory, but generally should not be larger than
508 16384 to realize any performance improvement.
</p>
510 <p>The
<a href='#cupsArrayNew3'
><code>cupsArrayNew3
</code></a> function adds
511 copy and free callbacks to support basic memory management of elements:
</p>
513 <pre class='example'
>
514 #include
<cups/array.h
>
516 #define HASH_SIZE
512 /* Size of hash table */
518 static int compare_func(void *first, void *second, void *user_data);
519 static void *copy_func(void *element, void *user_data);
520 static void free_func(void *element, void *user_data);
521 static int hash_func(void *element, void *user_data);
524 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew3'
>cupsArrayNew3
</a>(compare_func, user_data, NULL,
0, copy_func, free_func);
526 <a href='#cups_array_t'
>cups_array_t
</a> *hash_array =
<a href='#cupsArrayNew3'
>cupsArrayNew3
</a>(compare_func, user_data, hash_func, HASH_SIZE, copy_func, free_func);
529 <p>Once you have created the array, you add elements using the
530 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a>
531 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> functions.
532 The first function adds an element to the array, adding the new element
533 after any elements that have the same order, while the second inserts the
534 element before others with the same order. For unsorted arrays,
535 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a> appends the element to
536 the end of the array while
537 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> inserts the
538 element at the beginning of the array. For example, the following code
539 creates a sorted array of character strings:
</p>
541 <pre class='example'
>
542 #include
<cups/array.h
>
544 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
545 <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);
547 /* Add four strings to the array */
548 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
549 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
550 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
551 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
554 <p>Elements are removed using the
555 <a href='#cupsArrayRemove'
><code>cupsArrayRemove
</code></a> function, for
558 <pre class='example'
>
559 #include
<cups/array.h
>
561 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
562 <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);
564 /* Add four strings to the array */
565 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
566 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
567 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
568 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
570 /* Remove
"Red Fish" */
571 <a href='#cupsArrayRemove'
>cupsArrayRemove
</a>(array,
"Red Fish");
574 <p>Finally, you free the memory used by the array using the
575 <a href='#cupsArrayDelete'
><code>cupsArrayDelete
</code></a> function. All
576 of the memory for the array and hash table (if any) is freed, however
<em>CUPS
577 does not free the elements unless you provide copy and free functions
</em>.
</p>
579 <h3><a name='FINDING_AND_ENUMERATING'
>Finding and Enumerating Elements
</a></h3>
581 <p>CUPS provides several functions to find and enumerate elements in an
582 array. Each one sets or updates a
"current index" into the array, such that
583 future lookups will start where the last one left off:
</p>
586 <dt><a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a></dt>
587 <dd>Returns the first matching element.
</dd>
588 <dt><a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a></dt>
589 <dd>Returns the first element in the array.
</dd>
590 <dt><a href='#cupsArrayIndex'
><code>cupsArrayIndex
</code></a></dt>
591 <dd>Returns the Nth element in the array, starting at
0.
</dd>
592 <dt><a href='#cupsArrayLast'
><code>cupsArrayLast
</code></a></dt>
593 <dd>Returns the last element in the array.
</dd>
594 <dt><a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a></dt>
595 <dd>Returns the next element in the array.
</dd>
596 <dt><a href='#cupsArrayPrev'
><code>cupsArrayPrev
</code></a></dt>
597 <dd>Returns the previous element in the array.
</dd>
600 <p>Each of these functions returns
<code>NULL
</code> when there is no
601 corresponding element. For example, a simple
<code>for
</code> loop using the
602 <a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a> and
603 <a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a> functions will
604 enumerate all of the strings in our previous example:
</p>
606 <pre class='example'
>
607 #include
<cups/array.h
>
609 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
610 <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);
612 /* Add four strings to the array */
613 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
614 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
615 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
616 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
618 /* Show all of the strings in the array */
620 for (s = (char *)
<a href='#cupsArrayFirst'
>cupsArrayFirst
</a>(array); s != NULL; s = (char *)
<a href='#cupsArrayNext'
>cupsArrayNext
</a>(array))
623 <h2 class=
"title"><a id=
"FUNCTIONS">Functions
</a></h2>
624 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayAdd">cupsArrayAdd
</a></h3>
625 <p class=
"description">Add an element to the array.
</p>
627 int cupsArrayAdd (
<br />
628     <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br />
629     void *e
<br />
631 <h4 class=
"parameters">Parameters
</h4>
634 <dd class=
"description">Array
</dd>
636 <dd class=
"description">Element
</dd>
638 <h4 class=
"returnvalue">Return Value
</h4>
639 <p class=
"description">1 on success,
0 on failure
</p>
640 <h4 class=
"discussion">Discussion
</h4>
641 <p class=
"discussion">When adding an element to a sorted array, non-unique elements are
642 appended at the end of the run of identical elements. For unsorted arrays,
643 the element is appended to the end of the array.
646 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayClear">cupsArrayClear
</a></h3>
647 <p class=
"description">Clear the array.
</p>
649 void cupsArrayClear (
<br />
650     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
652 <h4 class=
"parameters">Parameters
</h4>
655 <dd class=
"description">Array
</dd>
657 <h4 class=
"discussion">Discussion
</h4>
658 <p class=
"discussion">This function is equivalent to removing all elements in the array.
659 The caller is responsible for freeing the memory used by the
663 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayCount">cupsArrayCount
</a></h3>
664 <p class=
"description">Get the number of elements in the array.
</p>
666 int cupsArrayCount (
<br />
667     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
669 <h4 class=
"parameters">Parameters
</h4>
672 <dd class=
"description">Array
</dd>
674 <h4 class=
"returnvalue">Return Value
</h4>
675 <p class=
"description">Number of elements
</p>
676 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayCurrent">cupsArrayCurrent
</a></h3>
677 <p class=
"description">Return the current element in the array.
</p>
679 void *cupsArrayCurrent (
<br />
680     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
682 <h4 class=
"parameters">Parameters
</h4>
685 <dd class=
"description">Array
</dd>
687 <h4 class=
"returnvalue">Return Value
</h4>
688 <p class=
"description">Element
</p>
689 <h4 class=
"discussion">Discussion
</h4>
690 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
691 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
694 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayDelete">cupsArrayDelete
</a></h3>
695 <p class=
"description">Free all memory used by the array.
</p>
697 void cupsArrayDelete (
<br />
698     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
700 <h4 class=
"parameters">Parameters
</h4>
703 <dd class=
"description">Array
</dd>
705 <h4 class=
"discussion">Discussion
</h4>
706 <p class=
"discussion">The caller is responsible for freeing the memory used by the
710 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayDup">cupsArrayDup
</a></h3>
711 <p class=
"description">Duplicate the array.
</p>
713 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayDup (
<br />
714     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
716 <h4 class=
"parameters">Parameters
</h4>
719 <dd class=
"description">Array
</dd>
721 <h4 class=
"returnvalue">Return Value
</h4>
722 <p class=
"description">Duplicate array
</p>
723 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayFind">cupsArrayFind
</a></h3>
724 <p class=
"description">Find an element in the array.
</p>
726 void *cupsArrayFind (
<br />
727     <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br />
728     void *e
<br />
730 <h4 class=
"parameters">Parameters
</h4>
733 <dd class=
"description">Array
</dd>
735 <dd class=
"description">Element
</dd>
737 <h4 class=
"returnvalue">Return Value
</h4>
738 <p class=
"description">Element found or
<code>NULL
</code></p>
739 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayFirst">cupsArrayFirst
</a></h3>
740 <p class=
"description">Get the first element in the array.
</p>
742 void *cupsArrayFirst (
<br />
743     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
745 <h4 class=
"parameters">Parameters
</h4>
748 <dd class=
"description">Array
</dd>
750 <h4 class=
"returnvalue">Return Value
</h4>
751 <p class=
"description">First element or
<code>NULL
</code> if the array is empty
</p>
752 <h3 class=
"function"><span class=
"info"> CUPS
1.3/macOS
10.5 </span><a id=
"cupsArrayGetIndex">cupsArrayGetIndex
</a></h3>
753 <p class=
"description">Get the index of the current element.
</p>
755 int cupsArrayGetIndex (
<br />
756     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
758 <h4 class=
"parameters">Parameters
</h4>
761 <dd class=
"description">Array
</dd>
763 <h4 class=
"returnvalue">Return Value
</h4>
764 <p class=
"description">Index of the current element, starting at
0</p>
765 <h4 class=
"discussion">Discussion
</h4>
766 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
767 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
770 <h3 class=
"function"><span class=
"info"> CUPS
1.3/macOS
10.5 </span><a id=
"cupsArrayGetInsert">cupsArrayGetInsert
</a></h3>
771 <p class=
"description">Get the index of the last inserted element.
</p>
773 int cupsArrayGetInsert (
<br />
774     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
776 <h4 class=
"parameters">Parameters
</h4>
779 <dd class=
"description">Array
</dd>
781 <h4 class=
"returnvalue">Return Value
</h4>
782 <p class=
"description">Index of the last inserted element, starting at
0</p>
783 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayIndex">cupsArrayIndex
</a></h3>
784 <p class=
"description">Get the N-th element in the array.
</p>
786 void *cupsArrayIndex (
<br />
787     <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br />
788     int n
<br />
790 <h4 class=
"parameters">Parameters
</h4>
793 <dd class=
"description">Array
</dd>
795 <dd class=
"description">Index into array, starting at
0</dd>
797 <h4 class=
"returnvalue">Return Value
</h4>
798 <p class=
"description">N-th element or
<code>NULL
</code></p>
799 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayInsert">cupsArrayInsert
</a></h3>
800 <p class=
"description">Insert an element in the array.
</p>
802 int cupsArrayInsert (
<br />
803     <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br />
804     void *e
<br />
806 <h4 class=
"parameters">Parameters
</h4>
809 <dd class=
"description">Array
</dd>
811 <dd class=
"description">Element
</dd>
813 <h4 class=
"returnvalue">Return Value
</h4>
814 <p class=
"description">0 on failure,
1 on success
</p>
815 <h4 class=
"discussion">Discussion
</h4>
816 <p class=
"discussion">When inserting an element in a sorted array, non-unique elements are
817 inserted at the beginning of the run of identical elements. For unsorted
818 arrays, the element is inserted at the beginning of the array.
821 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayLast">cupsArrayLast
</a></h3>
822 <p class=
"description">Get the last element in the array.
</p>
824 void *cupsArrayLast (
<br />
825     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
827 <h4 class=
"parameters">Parameters
</h4>
830 <dd class=
"description">Array
</dd>
832 <h4 class=
"returnvalue">Return Value
</h4>
833 <p class=
"description">Last element or
<code>NULL
</code> if the array is empty
</p>
834 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayNew">cupsArrayNew
</a></h3>
835 <p class=
"description">Create a new array.
</p>
837 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew (
<br />
838     <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br />
839     void *d
<br />
841 <h4 class=
"parameters">Parameters
</h4>
844 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
846 <dd class=
"description">User data pointer or
<code>NULL
</code></dd>
848 <h4 class=
"returnvalue">Return Value
</h4>
849 <p class=
"description">Array
</p>
850 <h4 class=
"discussion">Discussion
</h4>
851 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
852 receives pointers to two elements and the user data pointer (
"d
") - the user
853 data pointer argument can safely be omitted when not required so functions
854 like
<code>strcmp
</code> can be used for sorted string arrays.
857 <h3 class=
"function"><span class=
"info"> CUPS
1.3/macOS
10.5 </span><a id=
"cupsArrayNew2">cupsArrayNew2
</a></h3>
858 <p class=
"description">Create a new array with hash.
</p>
860 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew2 (
<br />
861     <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br />
862     void *d,
<br />
863     <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br />
864     int hsize
<br />
866 <h4 class=
"parameters">Parameters
</h4>
869 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
871 <dd class=
"description">User data or
<code>NULL
</code></dd>
873 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
875 <dd class=
"description">Hash size (
>=
0)
</dd>
877 <h4 class=
"returnvalue">Return Value
</h4>
878 <p class=
"description">Array
</p>
879 <h4 class=
"discussion">Discussion
</h4>
880 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
881 receives pointers to two elements and the user data pointer (
"d
") - the user
882 data pointer argument can safely be omitted when not required so functions
883 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
885 The hash function (
"h
") is used to implement cached lookups with the
886 specified hash size (
"hsize
").
889 <h3 class=
"function"><span class=
"info"> CUPS
1.5/macOS
10.7 </span><a id=
"cupsArrayNew3">cupsArrayNew3
</a></h3>
890 <p class=
"description">Create a new array with hash and/or free function.
</p>
892 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew3 (
<br />
893     <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br />
894     void *d,
<br />
895     <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br />
896     int hsize,
<br />
897     <a href=
"#cups_acopy_func_t">cups_acopy_func_t
</a> cf,
<br />
898     <a href=
"#cups_afree_func_t">cups_afree_func_t
</a> ff
<br />
900 <h4 class=
"parameters">Parameters
</h4>
903 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
905 <dd class=
"description">User data or
<code>NULL
</code></dd>
907 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
909 <dd class=
"description">Hash size (
>=
0)
</dd>
911 <dd class=
"description">Copy function
</dd>
913 <dd class=
"description">Free function
</dd>
915 <h4 class=
"returnvalue">Return Value
</h4>
916 <p class=
"description">Array
</p>
917 <h4 class=
"discussion">Discussion
</h4>
918 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
919 receives pointers to two elements and the user data pointer (
"d
") - the user
920 data pointer argument can safely be omitted when not required so functions
921 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
923 The hash function (
"h
") is used to implement cached lookups with the
924 specified hash size (
"hsize
").
<br>
926 The copy function (
"cf
") is used to automatically copy/retain elements when
927 added or the array is copied.
<br>
929 The free function (
"cf
") is used to automatically free/release elements when
930 removed or the array is deleted.
933 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayNext">cupsArrayNext
</a></h3>
934 <p class=
"description">Get the next element in the array.
</p>
936 void *cupsArrayNext (
<br />
937     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
939 <h4 class=
"parameters">Parameters
</h4>
942 <dd class=
"description">Array
</dd>
944 <h4 class=
"returnvalue">Return Value
</h4>
945 <p class=
"description">Next element or
<code>NULL
</code></p>
946 <h4 class=
"discussion">Discussion
</h4>
947 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) +
1)
".
<br>
949 The next element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
950 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
951 to set the current element.
954 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayPrev">cupsArrayPrev
</a></h3>
955 <p class=
"description">Get the previous element in the array.
</p>
957 void *cupsArrayPrev (
<br />
958     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
960 <h4 class=
"parameters">Parameters
</h4>
963 <dd class=
"description">Array
</dd>
965 <h4 class=
"returnvalue">Return Value
</h4>
966 <p class=
"description">Previous element or
<code>NULL
</code></p>
967 <h4 class=
"discussion">Discussion
</h4>
968 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) -
1)
".
<br>
970 The previous element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
971 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
972 to set the current element.
975 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayRemove">cupsArrayRemove
</a></h3>
976 <p class=
"description">Remove an element from the array.
</p>
978 int cupsArrayRemove (
<br />
979     <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br />
980     void *e
<br />
982 <h4 class=
"parameters">Parameters
</h4>
985 <dd class=
"description">Array
</dd>
987 <dd class=
"description">Element
</dd>
989 <h4 class=
"returnvalue">Return Value
</h4>
990 <p class=
"description">1 on success,
0 on failure
</p>
991 <h4 class=
"discussion">Discussion
</h4>
992 <p class=
"discussion">If more than one element matches
"e
", only the first matching element is
995 The caller is responsible for freeing the memory used by the
999 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayRestore">cupsArrayRestore
</a></h3>
1000 <p class=
"description">Reset the current element to the last
<a href=
"#cupsArraySave"><code>cupsArraySave
</code></a>.
</p>
1002 void *cupsArrayRestore (
<br />
1003     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
1005 <h4 class=
"parameters">Parameters
</h4>
1008 <dd class=
"description">Array
</dd>
1010 <h4 class=
"returnvalue">Return Value
</h4>
1011 <p class=
"description">New current element
</p>
1012 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArraySave">cupsArraySave
</a></h3>
1013 <p class=
"description">Mark the current element for a later
<a href=
"#cupsArrayRestore"><code>cupsArrayRestore
</code></a>.
</p>
1015 int cupsArraySave (
<br />
1016     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
1018 <h4 class=
"parameters">Parameters
</h4>
1021 <dd class=
"description">Array
</dd>
1023 <h4 class=
"returnvalue">Return Value
</h4>
1024 <p class=
"description">1 on success,
0 on failure
</p>
1025 <h4 class=
"discussion">Discussion
</h4>
1026 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
1027 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
1028 to set the current element.
<br>
1030 The save/restore stack is guaranteed to be at least
32 elements deep.
1033 <h3 class=
"function"><span class=
"info"> CUPS
1.2/macOS
10.5 </span><a id=
"cupsArrayUserData">cupsArrayUserData
</a></h3>
1034 <p class=
"description">Return the user data for an array.
</p>
1036 void *cupsArrayUserData (
<br />
1037     <a href=
"#cups_array_t">cups_array_t
</a> *a
<br />
1039 <h4 class=
"parameters">Parameters
</h4>
1042 <dd class=
"description">Array
</dd>
1044 <h4 class=
"returnvalue">Return Value
</h4>
1045 <p class=
"description">User data
</p>
1046 <h2 class=
"title"><a id=
"TYPES">Data Types
</a></h2>
1047 <h3 class=
"typedef"><a id=
"cups_acopy_func_t">cups_acopy_func_t
</a></h3>
1048 <p class=
"description">Array element copy function
</p>
1050 typedef void *(*cups_acopy_func_t)(void *element, void *data);
1052 <h3 class=
"typedef"><a id=
"cups_afree_func_t">cups_afree_func_t
</a></h3>
1053 <p class=
"description">Array element free function
</p>
1055 typedef void (*cups_afree_func_t)(void *element, void *data);
1057 <h3 class=
"typedef"><a id=
"cups_ahash_func_t">cups_ahash_func_t
</a></h3>
1058 <p class=
"description">Array hash function
</p>
1060 typedef int (*cups_ahash_func_t)(void *element, void *data);
1062 <h3 class=
"typedef"><a id=
"cups_array_func_t">cups_array_func_t
</a></h3>
1063 <p class=
"description">Array comparison function
</p>
1065 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
1067 <h3 class=
"typedef"><a id=
"cups_array_t">cups_array_t
</a></h3>
1068 <p class=
"description">CUPS array type
</p>
1070 typedef struct _cups_array_s cups_array_t;