summaryrefslogtreecommitdiff
path: root/cups/array.c
diff options
context:
space:
mode:
authorjlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be>2007-05-04 21:17:48 +0000
committerjlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be>2007-05-04 21:17:48 +0000
commitb94498cfba64422f0f21181b0c51cc0bed7c7d92 (patch)
treee3bdd0e05380bc8996f35ddb5439ab9044298712 /cups/array.c
parent323c5de1e804061e344172cc9a9551bb0ee71005 (diff)
downloadcups-b94498cfba64422f0f21181b0c51cc0bed7c7d92.tar.gz
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@321 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups/array.c')
-rw-r--r--cups/array.c74
1 files changed, 69 insertions, 5 deletions
diff --git a/cups/array.c b/cups/array.c
index b792c465c..50223a5ae 100644
--- a/cups/array.c
+++ b/cups/array.c
@@ -1,9 +1,9 @@
/*
- * "$Id: array.c 6123 2006-11-21 15:36:04Z mike $"
+ * "$Id: array.c 6477 2007-04-25 19:55:45Z mike $"
*
* Sorted array routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
@@ -90,6 +90,9 @@ struct _cups_array_s /**** CUPS array structure ****/
void **elements; /* Array elements */
cups_array_func_t compare; /* Element comparison function */
void *data; /* User data passed to compare */
+ cups_ahash_func_t hashfunc; /* Hash function */
+ int hashsize, /* Size of hash */
+ *hash; /* Hash array */
};
@@ -229,6 +232,9 @@ cupsArrayDelete(cups_array_t *a) /* I - Array */
if (a->alloc_elements)
free(a->elements);
+ if (a->hashsize)
+ free(a->hash);
+
free(a);
}
@@ -306,7 +312,8 @@ cupsArrayFind(cups_array_t *a, /* I - Array */
void *e) /* I - Element */
{
int current, /* Current element */
- diff; /* Difference */
+ diff, /* Difference */
+ hash; /* Hash index */
/*
@@ -327,7 +334,30 @@ cupsArrayFind(cups_array_t *a, /* I - Array */
* Yes, look for a match...
*/
- current = cups_array_find(a, e, a->current, &diff);
+ if (a->hash)
+ {
+ hash = (*(a->hashfunc))(e, a->data);
+
+ if (hash < 0 || hash >= a->hashsize)
+ {
+ current = a->current;
+ hash = -1;
+ }
+ else
+ {
+ current = a->hash[hash];
+
+ if (current < 0 || current >= a->num_elements)
+ current = a->current;
+ }
+ }
+ else
+ {
+ current = a->current;
+ hash = -1;
+ }
+
+ current = cups_array_find(a, e, current, &diff);
if (!diff)
{
/*
@@ -348,6 +378,9 @@ cupsArrayFind(cups_array_t *a, /* I - Array */
a->current = current;
+ if (hash >= 0)
+ a->hash[hash] = current;
+
return (a->elements[current]);
}
else
@@ -500,6 +533,22 @@ cups_array_t * /* O - Array */
cupsArrayNew(cups_array_func_t f, /* I - Comparison function */
void *d) /* I - User data */
{
+ return (cupsArrayNew2(f, d, 0, 0));
+}
+
+
+/*
+ * 'cupsArrayNew2()' - Create a new array with hash.
+ *
+ * @since CUPS 1.3@
+ */
+
+cups_array_t * /* O - Array */
+cupsArrayNew2(cups_array_func_t f, /* I - Comparison function */
+ void *d, /* I - User data */
+ cups_ahash_func_t h, /* I - Hash function*/
+ int hsize) /* I - Hash size */
+{
cups_array_t *a; /* Array */
@@ -518,6 +567,21 @@ cupsArrayNew(cups_array_func_t f, /* I - Comparison function */
a->num_saved = 0;
a->unique = 1;
+ if (hsize > 0 && h)
+ {
+ a->hashfunc = h;
+ a->hashsize = hsize;
+ a->hash = malloc(hsize * sizeof(int));
+
+ if (!a->hash)
+ {
+ free(a);
+ return (NULL);
+ }
+
+ memset(a->hash, -1, hsize * sizeof(int));
+ }
+
return (a);
}
@@ -998,5 +1062,5 @@ cups_array_find(cups_array_t *a, /* I - Array */
/*
- * End of "$Id: array.c 6123 2006-11-21 15:36:04Z mike $".
+ * End of "$Id: array.c 6477 2007-04-25 19:55:45Z mike $".
*/