2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2001-2009 Oracle. All rights reserved.
13 static int __db_idcmp __P((const void *, const void *));
36 * On input, minp and maxp contain the minimum and maximum valid values for
37 * the name space and on return, they contain the minimum and maximum ids
38 * available (by finding the biggest gap). The minimum can be an inuse
39 * value, but the maximum cannot be.
41 * PUBLIC: void __db_idspace __P((u_int32_t *, int, u_int32_t *, u_int32_t *));
44 __db_idspace(inuse, n, minp, maxp)
47 u_int32_t *minp, *maxp;
52 /* A single locker ID is a special case. */
55 * If the single item in use is the last one in the range,
56 * then we've got to perform wrap which means that we set
57 * the min to the minimum ID, which is what we came in with,
58 * so we don't do anything.
60 if (inuse[0] != *maxp)
68 qsort(inuse, (size_t)n, sizeof(u_int32_t), __db_idcmp);
69 for (i = 0; i < n - 1; i++)
70 if ((t = (inuse[i + 1] - inuse[i])) > gap) {
75 /* Check for largest gap at the end of the space. */
76 if ((*maxp - inuse[n - 1]) + (inuse[0] - *minp) > gap) {
77 /* Do same check as we do in the n == 1 case. */
78 if (inuse[n - 1] != *maxp)
83 *maxp = inuse[low + 1] - 1;