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 {
177 border-bottom: solid 2pt #000000;
180 DIV.indent, TABLE.indent {
188 border-collapse: collapse;
191 TABLE.indent TD, TABLE.indent TH {
196 border-collapse: collapse;
204 border-bottom: solid thin #cccccc;
209 vertical-align: bottom;
218 border-bottom: solid thin #eeeeee;
223 TABLE.list TR:nth-child(even) {
227 TABLE.list TR:nth-child(odd) {
246 font-family: monaco, courier, monospace;
250 border: solid thin #999999;
251 border-collapse: collapse;
256 DIV.summary TABLE TD, DIV.summary TABLE TH {
257 border: solid thin #999999;
263 DIV.summary TABLE THEAD TH {
267 /* API documentation styles... */
274 div.body h3, div.body h4, div.body h5 {
275 margin-bottom: 0.5em;
278 .class, .enumeration, .function, .struct, .typedef, .union {
279 border-bottom: solid thin #999999;
286 code, p.code, pre, ul.code li {
287 font-family: monaco, courier, monospace;
290 ul.code, ul.contents, ul.subcontents {
291 list-style-type: none;
301 ul.contents li ul.code, ul.contents li ul.subcontents {
314 margin-bottom: 0.5em;
317 /* This is just for the HTML files generated with the framedhelp target */
320 border: solid thin black;
329 div.contents ul.contents {
332 div.contents ul.subcontents li {
341 "$Id: api-array.header 8627 2009-05-13 21:39:17Z mike $"
343 Array API header for the Common UNIX Printing System (CUPS).
345 Copyright 2008-2009 by Apple Inc.
347 These coded instructions, statements, and computer programs are the
348 property of Apple Inc. and are protected by Federal copyright
349 law. Distribution and use rights are outlined in the file "LICENSE.txt"
350 which should have been included with this file. If this file is
351 file is missing or damaged, see the license at "http://www.cups.org/".
354 <h1 class='title'
>Array API
</h1>
356 <div class='summary'
><table summary='General Information'
>
360 <th>cups/array.h
</th>
370 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
374 <h2 class=
"title">Contents
</h2>
375 <ul class=
"contents">
376 <ul class=
"subcontents">
377 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
378 <li><a href=
"#MANAGING_ARRAYS">Managing Arrays
</a></li>
379 <li><a href=
"#FINDING_AND_ENUMERATING">Finding and Enumerating Elements
</a></li>
381 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
382 <li><a href=
"#cupsArrayAdd" title=
"Add an element to the array.">cupsArrayAdd
</a></li>
383 <li><a href=
"#cupsArrayClear" title=
"Clear the array.">cupsArrayClear
</a></li>
384 <li><a href=
"#cupsArrayCount" title=
"Get the number of elements in the array.">cupsArrayCount
</a></li>
385 <li><a href=
"#cupsArrayCurrent" title=
"Return the current element in the array.">cupsArrayCurrent
</a></li>
386 <li><a href=
"#cupsArrayDelete" title=
"Free all memory used by the array.">cupsArrayDelete
</a></li>
387 <li><a href=
"#cupsArrayDup" title=
"Duplicate the array.">cupsArrayDup
</a></li>
388 <li><a href=
"#cupsArrayFind" title=
"Find an element in the array.">cupsArrayFind
</a></li>
389 <li><a href=
"#cupsArrayFirst" title=
"Get the first element in the array.">cupsArrayFirst
</a></li>
390 <li><a href=
"#cupsArrayGetIndex" title=
"Get the index of the current element.">cupsArrayGetIndex
</a></li>
391 <li><a href=
"#cupsArrayGetInsert" title=
"Get the index of the last inserted element.">cupsArrayGetInsert
</a></li>
392 <li><a href=
"#cupsArrayIndex" title=
"Get the N-th element in the array.">cupsArrayIndex
</a></li>
393 <li><a href=
"#cupsArrayInsert" title=
"Insert an element in the array.">cupsArrayInsert
</a></li>
394 <li><a href=
"#cupsArrayLast" title=
"Get the last element in the array.">cupsArrayLast
</a></li>
395 <li><a href=
"#cupsArrayNew" title=
"Create a new array.">cupsArrayNew
</a></li>
396 <li><a href=
"#cupsArrayNew2" title=
"Create a new array with hash.">cupsArrayNew2
</a></li>
397 <li><a href=
"#cupsArrayNext" title=
"Get the next element in the array.">cupsArrayNext
</a></li>
398 <li><a href=
"#cupsArrayPrev" title=
"Get the previous element in the array.">cupsArrayPrev
</a></li>
399 <li><a href=
"#cupsArrayRemove" title=
"Remove an element from the array.">cupsArrayRemove
</a></li>
400 <li><a href=
"#cupsArrayRestore" title=
"Reset the current element to the last cupsArraySave.">cupsArrayRestore
</a></li>
401 <li><a href=
"#cupsArraySave" title=
"Mark the current element for a later cupsArrayRestore.">cupsArraySave
</a></li>
402 <li><a href=
"#cupsArrayUserData" title=
"Return the user data for an array.">cupsArrayUserData
</a></li>
404 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
405 <li><a href=
"#cups_ahash_func_t" title=
"Array hash function">cups_ahash_func_t
</a></li>
406 <li><a href=
"#cups_array_func_t" title=
"Array comparison function">cups_array_func_t
</a></li>
407 <li><a href=
"#cups_array_t" title=
"CUPS array type">cups_array_t
</a></li>
410 "$Id: api-array.shtml 7616 2008-05-28 00:34:13Z mike $"
412 Array API introduction for the Common UNIX Printing System (CUPS).
414 Copyright 2007-2008 by Apple Inc.
415 Copyright 1997-2006 by Easy Software Products, all rights reserved.
417 These coded instructions, statements, and computer programs are the
418 property of Apple Inc. and are protected by Federal copyright
419 law. Distribution and use rights are outlined in the file "LICENSE.txt"
420 which should have been included with this file. If this file is
421 file is missing or damaged, see the license at "http://www.cups.org/".
424 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
426 <p>The CUPS array API provides a high-performance generic array container.
427 The contents of the array container can be sorted and the container itself is
428 designed for optimal speed and memory usage under a wide variety of conditions.
429 Sorted arrays use a binary search algorithm from the last found or inserted
430 element to quickly find matching elements in the array. Arrays created with the
431 optional hash function can often find elements with a single lookup. The
432 <a href='#cups_array_t'
><code>cups_array_t
</code></a> type is used when
433 referring to a CUPS array.
</p>
435 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
436 functions use the array API to efficiently manage large lists of
439 <h3><a name='MANAGING_ARRAYS'
>Managing Arrays
</a></h3>
441 <p>Arrays are created using either the
442 <a href='#cupsArrayNew'
><code>cupsArrayNew
</code></a> or
443 <a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> functions. The
444 first function creates a new array with the specified callback function
445 and user data pointer:
</p>
447 <pre class='example'
>
448 #include
<cups/array.h
>
450 static int compare_func(void *first, void *second, void *user_data);
453 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>(compare_func, user_data);
456 <p>The comparison function (type
457 <a href=
"#cups_arrayfunc_t"><code>cups_arrayfunc_t
</code></a>) is called
458 whenever an element is added to the array and can be
<code>NULL
</code> to
459 create an unsorted array. The function returns -
1 if the first element should
460 come before the second,
0 if the first and second elements should have the same
461 ordering, and
1 if the first element should come after the second.
</p>
463 <p>The
"user_data" pointer is passed to your comparison function. Pass
464 <code>NULL
</code> if you do not need to associate the elements in your array
465 with additional information.
</p>
467 <p>The
<a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> function adds
468 two more arguments to support hashed lookups, which can potentially provide
469 instantaneous (
"O(1)") lookups in your array:
</p>
471 <pre class='example'
>
472 #include
<cups/array.h
>
474 #define HASH_SIZE
512 /* Size of hash table */
476 static int compare_func(void *first, void *second, void *user_data);
477 static int hash_func(void *element, void *user_data);
480 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew2'
>cupsArrayNew2
</a>(compare_func, user_data, hash_func, HASH_SIZE);
483 <p>The hash function (type
484 <a href=
"#cups_ahash_func_t"><code>cups_ahash_func_t
</code></a>) should return a
485 number from
0 to (hash_size-
1) that (hopefully) uniquely identifies the
486 element and is called whenever you look up an element in the array with
487 <a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a>. The hash size is
488 only limited by available memory, but generally should not be larger than
489 16384 to realize any performance improvement.
</p>
491 <p>Once you have created the array, you add elements using the
492 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a>
493 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> functions.
494 The first function adds an element to the array, adding the new element
495 after any elements that have the same order, while the second inserts the
496 element before others with the same order. For unsorted arrays,
497 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a> appends the element to
498 the end of the array while
499 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> inserts the
500 element at the beginning of the array. For example, the following code
501 creates a sorted array of character strings:
</p>
503 <pre class='example'
>
504 #include
<cups/array.h
>
506 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
507 <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);
509 /* Add four strings to the array */
510 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
511 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
512 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
513 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
516 <p>Elements are removed using the
517 <a href='#cupsArrayRemove'
><code>cupsArrayRemove
</code></a> function, for
520 <pre class='example'
>
521 #include
<cups/array.h
>
523 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
524 <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);
526 /* Add four strings to the array */
527 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
528 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
529 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
530 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
532 /* Remove
"Red Fish" */
533 <a href='#cupsArrayRemove'
>cupsArrayRemove
</a>(array,
"Red Fish");
536 <p>Finally, you free the memory used by the array using the
537 <a href='#cupsArrayDelete'
><code>cupsArrayDelete
</code></a> function. All
538 of the memory for the array and hash table (if any) is freed, however
<em>CUPS
539 does not free the elements
</em> - if necessary, you must allocate and free the
540 elements yourself.
</p>
542 <h3><a name='FINDING_AND_ENUMERATING'
>Finding and Enumerating Elements
</a></h3>
544 <p>CUPS provides several functions to find and enumerate elements in an
545 array. Each one sets or updates a
"current index" into the array, such that
546 future lookups will start where the last one left off:
</p>
549 <dt><a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a></dt>
550 <dd>Returns the first matching element.
</dd>
551 <dt><a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a></dt>
552 <dd>Returns the first element in the array.
</dd>
553 <dt><a href='#cupsArrayIndex'
><code>cupsArrayIndex
</code></a></dt>
554 <dd>Returns the Nth element in the array, starting at
0.
</dd>
555 <dt><a href='#cupsArrayLast'
><code>cupsArrayLast
</code></a></dt>
556 <dd>Returns the last element in the array.
</dd>
557 <dt><a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a></dt>
558 <dd>Returns the next element in the array.
</dd>
559 <dt><a href='#cupsArrayPrev'
><code>cupsArrayPrev
</code></a></dt>
560 <dd>Returns the previous element in the array.
</dd>
563 <p>Each of these functions returns
<code>NULL
</code> when there is no
564 corresponding element. For example, a simple
<code>for
</code> loop using the
565 <a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a> and
566 <a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a> functions will
567 enumerate all of the strings in our previous example:
</p>
569 <pre class='example'
>
570 #include
<cups/array.h
>
572 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
573 <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);
575 /* Add four strings to the array */
576 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
577 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
578 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
579 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
581 /* Show all of the strings in the array */
583 for (s = (char *)
<a href='#cupsArrayFirst'
>cupsArrayFirst
</a>(array); s != NULL; s = (char *)
<a href='#cupsArrayNext'
>cupsArrayNext
</a>(array))
586 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
587 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayAdd">cupsArrayAdd
</a></h3>
588 <p class=
"description">Add an element to the array.
</p>
590 int cupsArrayAdd (
<br>
591 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
592 void *e
<br>
594 <h4 class=
"parameters">Parameters
</h4>
597 <dd class=
"description">Array
</dd>
599 <dd class=
"description">Element
</dd>
601 <h4 class=
"returnvalue">Return Value
</h4>
602 <p class=
"description">1 on success,
0 on failure
</p>
603 <h4 class=
"discussion">Discussion
</h4>
604 <p class=
"discussion">When adding an element to a sorted array, non-unique elements are
605 appended at the end of the run of identical elements. For unsorted arrays,
606 the element is appended to the end of the array.
609 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayClear">cupsArrayClear
</a></h3>
610 <p class=
"description">Clear the array.
</p>
612 void cupsArrayClear (
<br>
613 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
615 <h4 class=
"parameters">Parameters
</h4>
618 <dd class=
"description">Array
</dd>
620 <h4 class=
"discussion">Discussion
</h4>
621 <p class=
"discussion">This function is equivalent to removing all elements in the array.
622 The caller is responsible for freeing the memory used by the
626 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayCount">cupsArrayCount
</a></h3>
627 <p class=
"description">Get the number of elements in the array.
</p>
629 int cupsArrayCount (
<br>
630 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
632 <h4 class=
"parameters">Parameters
</h4>
635 <dd class=
"description">Array
</dd>
637 <h4 class=
"returnvalue">Return Value
</h4>
638 <p class=
"description">Number of elements
</p>
639 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayCurrent">cupsArrayCurrent
</a></h3>
640 <p class=
"description">Return the current element in the array.
</p>
642 void *cupsArrayCurrent (
<br>
643 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
645 <h4 class=
"parameters">Parameters
</h4>
648 <dd class=
"description">Array
</dd>
650 <h4 class=
"returnvalue">Return Value
</h4>
651 <p class=
"description">Element
</p>
652 <h4 class=
"discussion">Discussion
</h4>
653 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
654 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
657 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayDelete">cupsArrayDelete
</a></h3>
658 <p class=
"description">Free all memory used by the array.
</p>
660 void cupsArrayDelete (
<br>
661 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
663 <h4 class=
"parameters">Parameters
</h4>
666 <dd class=
"description">Array
</dd>
668 <h4 class=
"discussion">Discussion
</h4>
669 <p class=
"discussion">The caller is responsible for freeing the memory used by the
673 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayDup">cupsArrayDup
</a></h3>
674 <p class=
"description">Duplicate the array.
</p>
676 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayDup (
<br>
677 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
679 <h4 class=
"parameters">Parameters
</h4>
682 <dd class=
"description">Array
</dd>
684 <h4 class=
"returnvalue">Return Value
</h4>
685 <p class=
"description">Duplicate array
</p>
686 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayFind">cupsArrayFind
</a></h3>
687 <p class=
"description">Find an element in the array.
</p>
689 void *cupsArrayFind (
<br>
690 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
691 void *e
<br>
693 <h4 class=
"parameters">Parameters
</h4>
696 <dd class=
"description">Array
</dd>
698 <dd class=
"description">Element
</dd>
700 <h4 class=
"returnvalue">Return Value
</h4>
701 <p class=
"description">Element found or
<code>NULL
</code></p>
702 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayFirst">cupsArrayFirst
</a></h3>
703 <p class=
"description">Get the first element in the array.
</p>
705 void *cupsArrayFirst (
<br>
706 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
708 <h4 class=
"parameters">Parameters
</h4>
711 <dd class=
"description">Array
</dd>
713 <h4 class=
"returnvalue">Return Value
</h4>
714 <p class=
"description">First element or
<code>NULL
</code> if the array is empty
</p>
715 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayGetIndex">cupsArrayGetIndex
</a></h3>
716 <p class=
"description">Get the index of the current element.
</p>
718 int cupsArrayGetIndex (
<br>
719 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
721 <h4 class=
"parameters">Parameters
</h4>
724 <dd class=
"description">Array
</dd>
726 <h4 class=
"returnvalue">Return Value
</h4>
727 <p class=
"description">Index of the current element, starting at
0</p>
728 <h4 class=
"discussion">Discussion
</h4>
729 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
730 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
733 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayGetInsert">cupsArrayGetInsert
</a></h3>
734 <p class=
"description">Get the index of the last inserted element.
</p>
736 int cupsArrayGetInsert (
<br>
737 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
739 <h4 class=
"parameters">Parameters
</h4>
742 <dd class=
"description">Array
</dd>
744 <h4 class=
"returnvalue">Return Value
</h4>
745 <p class=
"description">Index of the last inserted element, starting at
0</p>
746 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayIndex">cupsArrayIndex
</a></h3>
747 <p class=
"description">Get the N-th element in the array.
</p>
749 void *cupsArrayIndex (
<br>
750 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
751 int n
<br>
753 <h4 class=
"parameters">Parameters
</h4>
756 <dd class=
"description">Array
</dd>
758 <dd class=
"description">Index into array, starting at
0</dd>
760 <h4 class=
"returnvalue">Return Value
</h4>
761 <p class=
"description">N-th element or
<code>NULL
</code></p>
762 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayInsert">cupsArrayInsert
</a></h3>
763 <p class=
"description">Insert an element in the array.
</p>
765 int cupsArrayInsert (
<br>
766 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
767 void *e
<br>
769 <h4 class=
"parameters">Parameters
</h4>
772 <dd class=
"description">Array
</dd>
774 <dd class=
"description">Element
</dd>
776 <h4 class=
"returnvalue">Return Value
</h4>
777 <p class=
"description">0 on failure,
1 on success
</p>
778 <h4 class=
"discussion">Discussion
</h4>
779 <p class=
"discussion">When inserting an element in a sorted array, non-unique elements are
780 inserted at the beginning of the run of identical elements. For unsorted
781 arrays, the element is inserted at the beginning of the array.
784 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayLast">cupsArrayLast
</a></h3>
785 <p class=
"description">Get the last element in the array.
</p>
787 void *cupsArrayLast (
<br>
788 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
790 <h4 class=
"parameters">Parameters
</h4>
793 <dd class=
"description">Array
</dd>
795 <h4 class=
"returnvalue">Return Value
</h4>
796 <p class=
"description">Last element or
<code>NULL
</code> if the array is empty
</p>
797 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayNew">cupsArrayNew
</a></h3>
798 <p class=
"description">Create a new array.
</p>
800 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew (
<br>
801 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
802 void *d
<br>
804 <h4 class=
"parameters">Parameters
</h4>
807 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
809 <dd class=
"description">User data pointer or
<code>NULL
</code></dd>
811 <h4 class=
"returnvalue">Return Value
</h4>
812 <p class=
"description">Array
</p>
813 <h4 class=
"discussion">Discussion
</h4>
814 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
815 receives pointers to two elements and the user data pointer (
"d
") - the user
816 data pointer argument can safely be omitted when not required so functions
817 like
<code>strcmp
</code> can be used for sorted string arrays.
820 <h3 class=
"function"><span class=
"info"> CUPS
1.3/Mac OS X
10.5 </span><a name=
"cupsArrayNew2">cupsArrayNew2
</a></h3>
821 <p class=
"description">Create a new array with hash.
</p>
823 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew2 (
<br>
824 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
825 void *d,
<br>
826 <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br>
827 int hsize
<br>
829 <h4 class=
"parameters">Parameters
</h4>
832 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
834 <dd class=
"description">User data or
<code>NULL
</code></dd>
836 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
838 <dd class=
"description">Hash size (
>=
0)
</dd>
840 <h4 class=
"returnvalue">Return Value
</h4>
841 <p class=
"description">Array
</p>
842 <h4 class=
"discussion">Discussion
</h4>
843 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
844 receives pointers to two elements and the user data pointer (
"d
") - the user
845 data pointer argument can safely be omitted when not required so functions
846 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
848 The hash function (
"h
") is used to implement cached lookups with the
849 specified hash size (
"hsize
").
852 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayNext">cupsArrayNext
</a></h3>
853 <p class=
"description">Get the next element in the array.
</p>
855 void *cupsArrayNext (
<br>
856 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
858 <h4 class=
"parameters">Parameters
</h4>
861 <dd class=
"description">Array
</dd>
863 <h4 class=
"returnvalue">Return Value
</h4>
864 <p class=
"description">Next element or
<code>NULL
</code></p>
865 <h4 class=
"discussion">Discussion
</h4>
866 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) +
1)
".
<br>
868 The next element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
869 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
870 to set the current element.
873 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayPrev">cupsArrayPrev
</a></h3>
874 <p class=
"description">Get the previous element in the array.
</p>
876 void *cupsArrayPrev (
<br>
877 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
879 <h4 class=
"parameters">Parameters
</h4>
882 <dd class=
"description">Array
</dd>
884 <h4 class=
"returnvalue">Return Value
</h4>
885 <p class=
"description">Previous element or
<code>NULL
</code></p>
886 <h4 class=
"discussion">Discussion
</h4>
887 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) -
1)
".
<br>
889 The previous element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
890 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
891 to set the current element.
894 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayRemove">cupsArrayRemove
</a></h3>
895 <p class=
"description">Remove an element from the array.
</p>
897 int cupsArrayRemove (
<br>
898 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
899 void *e
<br>
901 <h4 class=
"parameters">Parameters
</h4>
904 <dd class=
"description">Array
</dd>
906 <dd class=
"description">Element
</dd>
908 <h4 class=
"returnvalue">Return Value
</h4>
909 <p class=
"description">1 on success,
0 on failure
</p>
910 <h4 class=
"discussion">Discussion
</h4>
911 <p class=
"discussion">If more than one element matches
"e
", only the first matching element is
914 The caller is responsible for freeing the memory used by the
918 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayRestore">cupsArrayRestore
</a></h3>
919 <p class=
"description">Reset the current element to the last
<a href=
"#cupsArraySave"><code>cupsArraySave
</code></a>.
</p>
921 void *cupsArrayRestore (
<br>
922 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
924 <h4 class=
"parameters">Parameters
</h4>
927 <dd class=
"description">Array
</dd>
929 <h4 class=
"returnvalue">Return Value
</h4>
930 <p class=
"description">New current element
</p>
931 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArraySave">cupsArraySave
</a></h3>
932 <p class=
"description">Mark the current element for a later
<a href=
"#cupsArrayRestore"><code>cupsArrayRestore
</code></a>.
</p>
934 int cupsArraySave (
<br>
935 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
937 <h4 class=
"parameters">Parameters
</h4>
940 <dd class=
"description">Array
</dd>
942 <h4 class=
"returnvalue">Return Value
</h4>
943 <p class=
"description">1 on success,
0 on failure
</p>
944 <h4 class=
"discussion">Discussion
</h4>
945 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
946 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
947 to set the current element.
<br>
949 The save/restore stack is guaranteed to be at least
32 elements deep.
952 <h3 class=
"function"><span class=
"info"> CUPS
1.2/Mac OS X
10.5 </span><a name=
"cupsArrayUserData">cupsArrayUserData
</a></h3>
953 <p class=
"description">Return the user data for an array.
</p>
955 void *cupsArrayUserData (
<br>
956 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
958 <h4 class=
"parameters">Parameters
</h4>
961 <dd class=
"description">Array
</dd>
963 <h4 class=
"returnvalue">Return Value
</h4>
964 <p class=
"description">User data
</p>
965 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
966 <h3 class=
"typedef"><a name=
"cups_ahash_func_t">cups_ahash_func_t
</a></h3>
967 <p class=
"description">Array hash function
</p>
969 typedef int (*cups_ahash_func_t)(void *element, void *data);
971 <h3 class=
"typedef"><a name=
"cups_array_func_t">cups_array_func_t
</a></h3>
972 <p class=
"description">Array comparison function
</p>
974 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
976 <h3 class=
"typedef"><a name=
"cups_array_t">cups_array_t
</a></h3>
977 <p class=
"description">CUPS array type
</p>
979 typedef struct _cups_array_s cups_array_t;