1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/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;
41 border: dotted thin #999999;
46 PRE.command EM, PRE.example EM {
47 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
51 font-family: monaco, courier, monospace;
62 border: solid thin #999999;
73 -moz-border-radius: 10px;
78 text-decoration: none;
81 A:link:hover, A:visited:hover, A:active {
82 text-decoration: underline;
89 TR.data, TD.data, TR.data TD {
92 border-bottom: solid 1pt #999999;
96 border-bottom: solid 1pt #999999;
103 border: solid thin #999999;
104 border-collapse: collapse;
120 border: solid thin #cccccc;
127 border-bottom: solid thin #999999;
136 caption-side: bottom;
160 border: thin solid black;
168 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
174 border-bottom: solid 2pt #000000;
177 DIV.indent, TABLE.indent {
185 border-collapse: collapse;
188 TABLE.indent TD, TABLE.indent TH {
193 border-collapse: collapse;
201 border-bottom: solid thin #cccccc;
206 vertical-align: bottom;
215 border-bottom: solid thin #eeeeee;
220 TABLE.list TR:nth-child(even) {
224 TABLE.list TR:nth-child(odd) {
243 font-family: monaco, courier, monospace;
247 border: solid thin #999999;
248 border-collapse: collapse;
253 DIV.summary TABLE TD, DIV.summary TABLE TH {
254 border: solid thin #999999;
260 DIV.summary TABLE THEAD TH {
264 /* API documentation styles... */
271 div.body h3, div.body h4, div.body h5 {
272 margin-bottom: 0.5em;
275 .class, .enumeration, .function, .struct, .typedef, .union {
276 border-bottom: solid thin #999999;
283 code, p.code, pre, ul.code li {
284 font-family: monaco, courier, monospace;
287 ul.code, ul.contents, ul.subcontents {
288 list-style-type: none;
298 ul.contents li ul.code, ul.contents li ul.subcontents {
311 margin-bottom: 0.5em;
314 /* This is just for the HTML files generated with the framedhelp target */
317 border: solid thin black;
326 div.contents ul.contents {
329 div.contents ul.subcontents li {
338 "$Id: api-array.header 8087 2008-10-27 21:37:05Z mike $"
340 Array API header for the Common UNIX Printing System (CUPS).
342 Copyright 2008 by Apple Inc.
344 These coded instructions, statements, and computer programs are the
345 property of Apple Inc. and are protected by Federal copyright
346 law. Distribution and use rights are outlined in the file "LICENSE.txt"
347 which should have been included with this file. If this file is
348 file is missing or damaged, see the license at "http://www.cups.org/".
351 <div class='summary'
><table summary='General Information'
>
355 <th>cups/array.h
</th>
365 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
369 <h2 class=
"title">Contents
</h2>
370 <ul class=
"contents">
371 <ul class=
"subcontents">
372 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
373 <li><a href=
"#MANAGING_ARRAYS">Managing Arrays
</a></li>
374 <li><a href=
"#FINDING_AND_ENUMERATING">Finding and Enumerating Elements
</a></li>
376 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
377 <li><a href=
"#cupsArrayAdd" title=
"Add an element to the array.">cupsArrayAdd
</a></li>
378 <li><a href=
"#cupsArrayClear" title=
"Clear the array.">cupsArrayClear
</a></li>
379 <li><a href=
"#cupsArrayCount" title=
"Get the number of elements in the array.">cupsArrayCount
</a></li>
380 <li><a href=
"#cupsArrayCurrent" title=
"Return the current element in the array.">cupsArrayCurrent
</a></li>
381 <li><a href=
"#cupsArrayDelete" title=
"Free all memory used by the array.">cupsArrayDelete
</a></li>
382 <li><a href=
"#cupsArrayDup" title=
"Duplicate the array.">cupsArrayDup
</a></li>
383 <li><a href=
"#cupsArrayFind" title=
"Find an element in the array.">cupsArrayFind
</a></li>
384 <li><a href=
"#cupsArrayFirst" title=
"Get the first element in the array.">cupsArrayFirst
</a></li>
385 <li><a href=
"#cupsArrayGetIndex" title=
"Get the index of the current element.">cupsArrayGetIndex
</a></li>
386 <li><a href=
"#cupsArrayGetInsert" title=
"Get the index of the last inserted element.">cupsArrayGetInsert
</a></li>
387 <li><a href=
"#cupsArrayIndex" title=
"Get the N-th element in the array.">cupsArrayIndex
</a></li>
388 <li><a href=
"#cupsArrayInsert" title=
"Insert an element in the array.">cupsArrayInsert
</a></li>
389 <li><a href=
"#cupsArrayLast" title=
"Get the last element in the array.">cupsArrayLast
</a></li>
390 <li><a href=
"#cupsArrayNew" title=
"Create a new array.">cupsArrayNew
</a></li>
391 <li><a href=
"#cupsArrayNew2" title=
"Create a new array with hash.">cupsArrayNew2
</a></li>
392 <li><a href=
"#cupsArrayNext" title=
"Get the next element in the array.">cupsArrayNext
</a></li>
393 <li><a href=
"#cupsArrayPrev" title=
"Get the previous element in the array.">cupsArrayPrev
</a></li>
394 <li><a href=
"#cupsArrayRemove" title=
"Remove an element from the array.">cupsArrayRemove
</a></li>
395 <li><a href=
"#cupsArrayRestore" title=
"Reset the current element to the last cupsArraySave.">cupsArrayRestore
</a></li>
396 <li><a href=
"#cupsArraySave" title=
"Mark the current element for a later cupsArrayRestore.">cupsArraySave
</a></li>
397 <li><a href=
"#cupsArrayUserData" title=
"Return the user data for an array.">cupsArrayUserData
</a></li>
399 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
400 <li><a href=
"#cups_ahash_func_t" title=
"Array hash function">cups_ahash_func_t
</a></li>
401 <li><a href=
"#cups_array_func_t" title=
"Array comparison function">cups_array_func_t
</a></li>
402 <li><a href=
"#cups_array_t" title=
"CUPS array type">cups_array_t
</a></li>
405 "$Id: api-array.shtml 7616 2008-05-28 00:34:13Z mike $"
407 Array API introduction for the Common UNIX Printing System (CUPS).
409 Copyright 2007-2008 by Apple Inc.
410 Copyright 1997-2006 by Easy Software Products, all rights reserved.
412 These coded instructions, statements, and computer programs are the
413 property of Apple Inc. and are protected by Federal copyright
414 law. Distribution and use rights are outlined in the file "LICENSE.txt"
415 which should have been included with this file. If this file is
416 file is missing or damaged, see the license at "http://www.cups.org/".
419 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
421 <p>The CUPS array API provides a high-performance generic array container.
422 The contents of the array container can be sorted and the container itself is
423 designed for optimal speed and memory usage under a wide variety of conditions.
424 Sorted arrays use a binary search algorithm from the last found or inserted
425 element to quickly find matching elements in the array. Arrays created with the
426 optional hash function can often find elements with a single lookup. The
427 <a href='#cups_array_t'
><code>cups_array_t
</code></a> type is used when
428 referring to a CUPS array.
</p>
430 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
431 functions use the array API to efficiently manage large lists of
434 <h3><a name='MANAGING_ARRAYS'
>Managing Arrays
</a></h3>
436 <p>Arrays are created using either the
437 <a href='#cupsArrayNew'
><code>cupsArrayNew
</code></a> or
438 <a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> functions. The
439 first function creates a new array with the specified callback function
440 and user data pointer:
</p>
442 <pre class='example'
>
443 #include
<cups/array.h
>
445 static int compare_func(void *first, void *second, void *user_data);
448 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>(compare_func, user_data);
451 <p>The comparison function (type
452 <a href=
"#cups_arrayfunc_t"><code>cups_arrayfunc_t
</code></a>) is called
453 whenever an element is added to the array and can be
<code>NULL
</code> to
454 create an unsorted array. The function returns -
1 if the first element should
455 come before the second,
0 if the first and second elements should have the same
456 ordering, and
1 if the first element should come after the second.
</p>
458 <p>The
"user_data" pointer is passed to your comparison function. Pass
459 <code>NULL
</code> if you do not need to associate the elements in your array
460 with additional information.
</p>
462 <p>The
<a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> function adds
463 two more arguments to support hashed lookups, which can potentially provide
464 instantaneous (
"O(1)") lookups in your array:
</p>
466 <pre class='example'
>
467 #include
<cups/array.h
>
469 #define HASH_SIZE
512 /* Size of hash table */
471 static int compare_func(void *first, void *second, void *user_data);
472 static int hash_func(void *element, void *user_data);
475 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew2'
>cupsArrayNew2
</a>(compare_func, user_data, hash_func, HASH_SIZE);
478 <p>The hash function (type
479 <a href=
"#cups_ahash_func_t"><code>cups_ahash_func_t
</code></a>) should return a
480 number from
0 to (hash_size-
1) that (hopefully) uniquely identifies the
481 element and is called whenever you look up an element in the array with
482 <a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a>. The hash size is
483 only limited by available memory, but generally should not be larger than
484 16384 to realize any performance improvement.
</p>
486 <p>Once you have created the array, you add elements using the
487 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a>
488 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> functions.
489 The first function adds an element to the array, adding the new element
490 after any elements that have the same order, while the second inserts the
491 element before others with the same order. For unsorted arrays,
492 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a> appends the element to
493 the end of the array while
494 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> inserts the
495 element at the beginning of the array. For example, the following code
496 creates a sorted array of character strings:
</p>
498 <pre class='example'
>
499 #include
<cups/array.h
>
501 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
502 <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);
504 /* Add four strings to the array */
505 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
506 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
507 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
508 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
511 <p>Elements are removed using the
512 <a href='#cupsArrayRemove'
><code>cupsArrayRemove
</code></a> function, for
515 <pre class='example'
>
516 #include
<cups/array.h
>
518 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
519 <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);
521 /* Add four strings to the array */
522 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
523 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
524 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
525 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
527 /* Remove
"Red Fish" */
528 <a href='#cupsArrayRemove'
>cupsArrayRemove
</a>(array,
"Red Fish");
531 <p>Finally, you free the memory used by the array using the
532 <a href='#cupsArrayDelete'
><code>cupsArrayDelete
</code></a> function. All
533 of the memory for the array and hash table (if any) is freed, however
<em>CUPS
534 does not free the elements
</em> - if necessary, you must allocate and free the
535 elements yourself.
</p>
537 <h3><a name='FINDING_AND_ENUMERATING'
>Finding and Enumerating Elements
</a></h3>
539 <p>CUPS provides several functions to find and enumerate elements in an
540 array. Each one sets or updates a
"current index" into the array, such that
541 future lookups will start where the last one left off:
</p>
544 <dt><a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a></dt>
545 <dd>Returns the first matching element.
</dd>
546 <dt><a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a></dt>
547 <dd>Returns the first element in the array.
</dd>
548 <dt><a href='#cupsArrayIndex'
><code>cupsArrayIndex
</code></a></dt>
549 <dd>Returns the Nth element in the array, starting at
0.
</dd>
550 <dt><a href='#cupsArrayLast'
><code>cupsArrayLast
</code></a></dt>
551 <dd>Returns the last element in the array.
</dd>
552 <dt><a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a></dt>
553 <dd>Returns the next element in the array.
</dd>
554 <dt><a href='#cupsArrayPrev'
><code>cupsArrayPrev
</code></a></dt>
555 <dd>Returns the previous element in the array.
</dd>
558 <p>Each of these functions returns
<code>NULL
</code> when there is no
559 corresponding element. For example, a simple
<code>for
</code> loop using the
560 <a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a> and
561 <a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a> functions will
562 enumerate all of the strings in our previous example:
</p>
564 <pre class='example'
>
565 #include
<cups/array.h
>
567 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
568 <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);
570 /* Add four strings to the array */
571 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
572 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
573 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
574 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
576 /* Show all of the strings in the array */
578 for (s = (char *)
<a href='#cupsArrayFirst'
>cupsArrayFirst
</a>(array); s != NULL; s = (char *)
<a href='#cupsArrayNext'
>cupsArrayNext
</a>(array))
581 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
582 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayAdd">cupsArrayAdd
</a></h3>
583 <p class=
"description">Add an element to the array.
</p>
585 int cupsArrayAdd (
<br>
586 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
587 void *e
<br>
589 <h4 class=
"parameters">Parameters
</h4>
592 <dd class=
"description">Array
</dd>
594 <dd class=
"description">Element
</dd>
596 <h4 class=
"returnvalue">Return Value
</h4>
597 <p class=
"description">1 on success,
0 on failure
</p>
598 <h4 class=
"discussion">Discussion
</h4>
599 <p class=
"discussion">When adding an element to a sorted array, non-unique elements are
600 appended at the end of the run of identical elements. For unsorted arrays,
601 the element is appended to the end of the array.
604 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayClear">cupsArrayClear
</a></h3>
605 <p class=
"description">Clear the array.
</p>
607 void cupsArrayClear (
<br>
608 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
610 <h4 class=
"parameters">Parameters
</h4>
613 <dd class=
"description">Array
</dd>
615 <h4 class=
"discussion">Discussion
</h4>
616 <p class=
"discussion">This function is equivalent to removing all elements in the array.
617 The caller is responsible for freeing the memory used by the
621 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayCount">cupsArrayCount
</a></h3>
622 <p class=
"description">Get the number of elements in the array.
</p>
624 int cupsArrayCount (
<br>
625 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
627 <h4 class=
"parameters">Parameters
</h4>
630 <dd class=
"description">Array
</dd>
632 <h4 class=
"returnvalue">Return Value
</h4>
633 <p class=
"description">Number of elements
</p>
634 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayCurrent">cupsArrayCurrent
</a></h3>
635 <p class=
"description">Return the current element in the array.
</p>
637 void *cupsArrayCurrent (
<br>
638 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
640 <h4 class=
"parameters">Parameters
</h4>
643 <dd class=
"description">Array
</dd>
645 <h4 class=
"returnvalue">Return Value
</h4>
646 <p class=
"description">Element
</p>
647 <h4 class=
"discussion">Discussion
</h4>
648 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
649 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
652 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayDelete">cupsArrayDelete
</a></h3>
653 <p class=
"description">Free all memory used by the array.
</p>
655 void cupsArrayDelete (
<br>
656 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
658 <h4 class=
"parameters">Parameters
</h4>
661 <dd class=
"description">Array
</dd>
663 <h4 class=
"discussion">Discussion
</h4>
664 <p class=
"discussion">The caller is responsible for freeing the memory used by the
668 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayDup">cupsArrayDup
</a></h3>
669 <p class=
"description">Duplicate the array.
</p>
671 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayDup (
<br>
672 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
674 <h4 class=
"parameters">Parameters
</h4>
677 <dd class=
"description">Array
</dd>
679 <h4 class=
"returnvalue">Return Value
</h4>
680 <p class=
"description">Duplicate array
</p>
681 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayFind">cupsArrayFind
</a></h3>
682 <p class=
"description">Find an element in the array.
</p>
684 void *cupsArrayFind (
<br>
685 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
686 void *e
<br>
688 <h4 class=
"parameters">Parameters
</h4>
691 <dd class=
"description">Array
</dd>
693 <dd class=
"description">Element
</dd>
695 <h4 class=
"returnvalue">Return Value
</h4>
696 <p class=
"description">Element found or
<code>NULL
</code></p>
697 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayFirst">cupsArrayFirst
</a></h3>
698 <p class=
"description">Get the first element in the array.
</p>
700 void *cupsArrayFirst (
<br>
701 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
703 <h4 class=
"parameters">Parameters
</h4>
706 <dd class=
"description">Array
</dd>
708 <h4 class=
"returnvalue">Return Value
</h4>
709 <p class=
"description">First element or
<code>NULL
</code> if the array is empty
</p>
710 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayGetIndex">cupsArrayGetIndex
</a></h3>
711 <p class=
"description">Get the index of the current element.
</p>
713 int cupsArrayGetIndex (
<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">Index of the current element, starting at
0</p>
723 <h4 class=
"discussion">Discussion
</h4>
724 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
725 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
728 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayGetInsert">cupsArrayGetInsert
</a></h3>
729 <p class=
"description">Get the index of the last inserted element.
</p>
731 int cupsArrayGetInsert (
<br>
732 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
734 <h4 class=
"parameters">Parameters
</h4>
737 <dd class=
"description">Array
</dd>
739 <h4 class=
"returnvalue">Return Value
</h4>
740 <p class=
"description">Index of the last inserted element, starting at
0</p>
741 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayIndex">cupsArrayIndex
</a></h3>
742 <p class=
"description">Get the N-th element in the array.
</p>
744 void *cupsArrayIndex (
<br>
745 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
746 int n
<br>
748 <h4 class=
"parameters">Parameters
</h4>
751 <dd class=
"description">Array
</dd>
753 <dd class=
"description">Index into array, starting at
0</dd>
755 <h4 class=
"returnvalue">Return Value
</h4>
756 <p class=
"description">N-th element or
<code>NULL
</code></p>
757 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayInsert">cupsArrayInsert
</a></h3>
758 <p class=
"description">Insert an element in the array.
</p>
760 int cupsArrayInsert (
<br>
761 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
762 void *e
<br>
764 <h4 class=
"parameters">Parameters
</h4>
767 <dd class=
"description">Array
</dd>
769 <dd class=
"description">Element
</dd>
771 <h4 class=
"returnvalue">Return Value
</h4>
772 <p class=
"description">0 on failure,
1 on success
</p>
773 <h4 class=
"discussion">Discussion
</h4>
774 <p class=
"discussion">When inserting an element in a sorted array, non-unique elements are
775 inserted at the beginning of the run of identical elements. For unsorted
776 arrays, the element is inserted at the beginning of the array.
779 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayLast">cupsArrayLast
</a></h3>
780 <p class=
"description">Get the last element in the array.
</p>
782 void *cupsArrayLast (
<br>
783 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
785 <h4 class=
"parameters">Parameters
</h4>
788 <dd class=
"description">Array
</dd>
790 <h4 class=
"returnvalue">Return Value
</h4>
791 <p class=
"description">Last element or
<code>NULL
</code> if the array is empty
</p>
792 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayNew">cupsArrayNew
</a></h3>
793 <p class=
"description">Create a new array.
</p>
795 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew (
<br>
796 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
797 void *d
<br>
799 <h4 class=
"parameters">Parameters
</h4>
802 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
804 <dd class=
"description">User data pointer or
<code>NULL
</code></dd>
806 <h4 class=
"returnvalue">Return Value
</h4>
807 <p class=
"description">Array
</p>
808 <h4 class=
"discussion">Discussion
</h4>
809 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
810 receives pointers to two elements and the user data pointer (
"d
") - the user
811 data pointer argument can safely be omitted when not required so functions
812 like
<code>strcmp
</code> can be used for sorted string arrays.
815 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayNew2">cupsArrayNew2
</a></h3>
816 <p class=
"description">Create a new array with hash.
</p>
818 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew2 (
<br>
819 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
820 void *d,
<br>
821 <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br>
822 int hsize
<br>
824 <h4 class=
"parameters">Parameters
</h4>
827 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
829 <dd class=
"description">User data or
<code>NULL
</code></dd>
831 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
833 <dd class=
"description">Hash size (
>=
0)
</dd>
835 <h4 class=
"returnvalue">Return Value
</h4>
836 <p class=
"description">Array
</p>
837 <h4 class=
"discussion">Discussion
</h4>
838 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
839 receives pointers to two elements and the user data pointer (
"d
") - the user
840 data pointer argument can safely be omitted when not required so functions
841 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
843 The hash function (
"h
") is used to implement cached lookups with the
844 specified hash size (
"hsize
").
847 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayNext">cupsArrayNext
</a></h3>
848 <p class=
"description">Get the next element in the array.
</p>
850 void *cupsArrayNext (
<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">Next element or
<code>NULL
</code></p>
860 <h4 class=
"discussion">Discussion
</h4>
861 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) +
1)
".
<br>
863 The next element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
864 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
865 to set the current element.
868 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayPrev">cupsArrayPrev
</a></h3>
869 <p class=
"description">Get the previous element in the array.
</p>
871 void *cupsArrayPrev (
<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">Previous element or
<code>NULL
</code></p>
881 <h4 class=
"discussion">Discussion
</h4>
882 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) -
1)
".
<br>
884 The previous element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
885 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
886 to set the current element.
889 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayRemove">cupsArrayRemove
</a></h3>
890 <p class=
"description">Remove an element from the array.
</p>
892 int cupsArrayRemove (
<br>
893 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
894 void *e
<br>
896 <h4 class=
"parameters">Parameters
</h4>
899 <dd class=
"description">Array
</dd>
901 <dd class=
"description">Element
</dd>
903 <h4 class=
"returnvalue">Return Value
</h4>
904 <p class=
"description">1 on success,
0 on failure
</p>
905 <h4 class=
"discussion">Discussion
</h4>
906 <p class=
"discussion">If more than one element matches
"e
", only the first matching element is
909 The caller is responsible for freeing the memory used by the
913 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayRestore">cupsArrayRestore
</a></h3>
914 <p class=
"description">Reset the current element to the last
<a href=
"#cupsArraySave"><code>cupsArraySave
</code></a>.
</p>
916 void *cupsArrayRestore (
<br>
917 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
919 <h4 class=
"parameters">Parameters
</h4>
922 <dd class=
"description">Array
</dd>
924 <h4 class=
"returnvalue">Return Value
</h4>
925 <p class=
"description">New current element
</p>
926 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArraySave">cupsArraySave
</a></h3>
927 <p class=
"description">Mark the current element for a later
<a href=
"#cupsArrayRestore"><code>cupsArrayRestore
</code></a>.
</p>
929 int cupsArraySave (
<br>
930 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
932 <h4 class=
"parameters">Parameters
</h4>
935 <dd class=
"description">Array
</dd>
937 <h4 class=
"returnvalue">Return Value
</h4>
938 <p class=
"description">1 on success,
0 on failure
</p>
939 <h4 class=
"discussion">Discussion
</h4>
940 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
941 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
942 to set the current element.
<br>
944 The save/restore stack is guaranteed to be at least
32 elements deep.
947 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayUserData">cupsArrayUserData
</a></h3>
948 <p class=
"description">Return the user data for an array.
</p>
950 void *cupsArrayUserData (
<br>
951 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
953 <h4 class=
"parameters">Parameters
</h4>
956 <dd class=
"description">Array
</dd>
958 <h4 class=
"returnvalue">Return Value
</h4>
959 <p class=
"description">User data
</p>
960 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
961 <h3 class=
"typedef"><a name=
"cups_ahash_func_t">cups_ahash_func_t
</a></h3>
962 <p class=
"description">Array hash function
</p>
964 typedef int (*cups_ahash_func_t)(void *element, void *data);
966 <h3 class=
"typedef"><a name=
"cups_array_func_t">cups_array_func_t
</a></h3>
967 <p class=
"description">Array comparison function
</p>
969 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
971 <h3 class=
"typedef"><a name=
"cups_array_t">cups_array_t
</a></h3>
972 <p class=
"description">CUPS array type
</p>
974 typedef struct _cups_array_s cups_array_t;