Software: Apache/2.2.16 (Debian). PHP/5.3.3-7+squeeze19 uname -a: Linux mail.tri-specialutilitydistrict.com 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/cups/doc-root/help/ drwxr-xr-x |
Viewing file: Select action/file-type: Array API
Contents
OverviewThe CUPS array API provides a high-performance generic array container.
The contents of the array container can be sorted and the container itself is
designed for optimal speed and memory usage under a wide variety of conditions.
Sorted arrays use a binary search algorithm from the last found or inserted
element to quickly find matching elements in the array. Arrays created with the
optional hash function can often find elements with a single lookup. The
The CUPS scheduler (cupsd) and many of the CUPS API functions use the array API to efficiently manage large lists of data. Managing ArraysArrays are created using either the
#include <cups/array.h> static int compare_func(void *first, void *second, void *user_data); void *user_data; cups_array_t *array = cupsArrayNew(compare_func, user_data); The comparison function (type
The "user_data" pointer is passed to your comparison function. Pass
The #include <cups/array.h> #define HASH_SIZE 512 /* Size of hash table */ static int compare_func(void *first, void *second, void *user_data); static int hash_func(void *element, void *user_data); void *user_data; cups_array_t *array = cupsArrayNew2(compare_func, user_data, hash_func, HASH_SIZE); The hash function (type
Once you have created the array, you add elements using the
#include <cups/array.h> /* Use strcmp() to compare strings - it will ignore the user_data pointer */ cups_array_t *array = cupsArrayNew((cups_array_func_t)strcmp, NULL); /* Add four strings to the array */ cupsArrayAdd(array, "One Fish"); cupsArrayAdd(array, "Two Fish"); cupsArrayAdd(array, "Red Fish"); cupsArrayAdd(array, "Blue Fish"); Elements are removed using the
#include <cups/array.h> /* Use strcmp() to compare strings - it will ignore the user_data pointer */ cups_array_t *array = cupsArrayNew((cups_array_func_t)strcmp, NULL); /* Add four strings to the array */ cupsArrayAdd(array, "One Fish"); cupsArrayAdd(array, "Two Fish"); cupsArrayAdd(array, "Red Fish"); cupsArrayAdd(array, "Blue Fish"); /* Remove "Red Fish" */ cupsArrayRemove(array, "Red Fish"); Finally, you free the memory used by the array using the
Finding and Enumerating ElementsCUPS provides several functions to find and enumerate elements in an array. Each one sets or updates a "current index" into the array, such that future lookups will start where the last one left off:
Each of these functions returns #include <cups/array.h> /* Use strcmp() to compare strings - it will ignore the user_data pointer */ cups_array_t *array = cupsArrayNew((cups_array_func_t)strcmp, NULL); /* Add four strings to the array */ cupsArrayAdd(array, "One Fish"); cupsArrayAdd(array, "Two Fish"); cupsArrayAdd(array, "Red Fish"); cupsArrayAdd(array, "Blue Fish"); /* Show all of the strings in the array */ char *s; for (s = (char *)cupsArrayFirst(array); s != NULL; s = (char *)cupsArrayNext(array)) puts(s); FunctionsCUPS 1.2/Mac OS X 10.5 cupsArrayAddAdd an element to the array.
int cupsArrayAdd ( Parameters
Return Value1 on success, 0 on failure DiscussionWhen adding an element to a sorted array, non-unique elements are appended at the end of the run of identical elements. For unsorted arrays, the element is appended to the end of the array. CUPS 1.2/Mac OS X 10.5 cupsArrayClearClear the array.
void cupsArrayClear ( Parameters
DiscussionThis function is equivalent to removing all elements in the array. The caller is responsible for freeing the memory used by the elements themselves. CUPS 1.2/Mac OS X 10.5 cupsArrayCountGet the number of elements in the array.
int cupsArrayCount ( Parameters
Return ValueNumber of elements CUPS 1.2/Mac OS X 10.5 cupsArrayCurrentReturn the current element in the array.
void *cupsArrayCurrent ( Parameters
Return ValueElement DiscussionThe current element is undefined until you call CUPS 1.2/Mac OS X 10.5 cupsArrayDeleteFree all memory used by the array.
void cupsArrayDelete ( Parameters
DiscussionThe caller is responsible for freeing the memory used by the elements themselves. CUPS 1.2/Mac OS X 10.5 cupsArrayDupDuplicate the array.
cups_array_t *cupsArrayDup ( Parameters
Return ValueDuplicate array CUPS 1.2/Mac OS X 10.5 cupsArrayFindFind an element in the array.
void *cupsArrayFind ( Parameters
Return ValueElement found or CUPS 1.2/Mac OS X 10.5 cupsArrayFirstGet the first element in the array.
void *cupsArrayFirst ( Parameters
Return ValueFirst element or CUPS 1.3/Mac OS X 10.5 cupsArrayGetIndexGet the index of the current element.
int cupsArrayGetIndex ( Parameters
Return ValueIndex of the current element, starting at 0 DiscussionThe current element is undefined until you call CUPS 1.3/Mac OS X 10.5 cupsArrayGetInsertGet the index of the last inserted element.
int cupsArrayGetInsert ( Parameters
Return ValueIndex of the last inserted element, starting at 0 CUPS 1.2/Mac OS X 10.5 cupsArrayIndexGet the N-th element in the array.
void *cupsArrayIndex ( Parameters
Return ValueN-th element or CUPS 1.2/Mac OS X 10.5 cupsArrayInsertInsert an element in the array.
int cupsArrayInsert ( Parameters
Return Value0 on failure, 1 on success DiscussionWhen inserting an element in a sorted array, non-unique elements are inserted at the beginning of the run of identical elements. For unsorted arrays, the element is inserted at the beginning of the array. CUPS 1.2/Mac OS X 10.5 cupsArrayLastGet the last element in the array.
void *cupsArrayLast ( Parameters
Return ValueLast element or CUPS 1.2/Mac OS X 10.5 cupsArrayNewCreate a new array.
cups_array_t *cupsArrayNew ( Parameters
Return ValueArray DiscussionThe comparison function ("f") is used to create a sorted array. The function
receives pointers to two elements and the user data pointer ("d") - the user
data pointer argument can safely be omitted when not required so functions
like CUPS 1.3/Mac OS X 10.5 cupsArrayNew2Create a new array with hash.
cups_array_t *cupsArrayNew2 ( Parameters
Return ValueArray DiscussionThe comparison function ("f") is used to create a sorted array. The function
receives pointers to two elements and the user data pointer ("d") - the user
data pointer argument can safely be omitted when not required so functions
like CUPS 1.2/Mac OS X 10.5 cupsArrayNextGet the next element in the array.
void *cupsArrayNext ( Parameters
Return ValueNext element or DiscussionThis function is equivalent to "cupsArrayIndex(a, cupsArrayGetIndex(a) + 1)". CUPS 1.2/Mac OS X 10.5 cupsArrayPrevGet the previous element in the array.
void *cupsArrayPrev ( Parameters
Return ValuePrevious element or DiscussionThis function is equivalent to "cupsArrayIndex(a, cupsArrayGetIndex(a) - 1)". CUPS 1.2/Mac OS X 10.5 cupsArrayRemoveRemove an element from the array.
int cupsArrayRemove ( Parameters
Return Value1 on success, 0 on failure DiscussionIf more than one element matches "e", only the first matching element is
removed. CUPS 1.2/Mac OS X 10.5 cupsArrayRestoreReset the current element to the last
void *cupsArrayRestore ( Parameters
Return ValueNew current element CUPS 1.2/Mac OS X 10.5 cupsArraySaveMark the current element for a later
int cupsArraySave ( Parameters
Return Value1 on success, 0 on failure DiscussionThe current element is undefined until you call CUPS 1.2/Mac OS X 10.5 cupsArrayUserDataReturn the user data for an array.
void *cupsArrayUserData ( Parameters
Return ValueUser data Data Typescups_ahash_func_tArray hash function typedef int (*cups_ahash_func_t)(void *element, void *data); cups_array_func_tArray comparison function typedef int (*cups_array_func_t)(void *first, void *second, void *data); cups_array_tCUPS array type typedef struct _cups_array_s cups_array_t; |
:: Command execute :: | |
--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0154 ]-- |