/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "volume_dlist.h"
#define _volume_dlist_C
/*
* public constant definitions
*/
/*
* determine if the list contains an item
* that points at the object
*/
void *obj,
int (compare)(void *, void *))
{
}
/*
* locate the item in the list that points at the object
*/
dlist_t *
void *obj,
int (compare)(void *, void *))
{
return (iter);
}
}
return (NULL);
}
/*
* insert item into list in the desired order (ascending or descending)
* using the comparison function provided.
*
* In the for loop, iter marks current position in the list
* and item is the item to be inserted.
*
* Iterate the list and find the correct place to insert temp.
*
* if (ascending && compare(item, iter) <= 0 ||
* (descending && compare(item, iter) >= 0)
* item goes before iter
* else
* item goes after iter
*/
dlist_t *
int (compare)(void *, void *))
{
int result = 0;
} else {
} else {
}
break;
}
/* end of list, so item becomes the new end */
break;
}
}
}
return (head);
}
/*
* Remove the first node pointing to same content as item from list,
* clear it's next and prev pointers, return new list head.
*
* The caller is responsible for freeing the removed item if it is no
* longer needed.
*
* The comparison function should be of the form:
*
* int compare(void *obj1, void* obj2);
*
* When called, obj1 will be the object passed into
* dlist_remove_equivalent_item and obj2 will be an object pointed to
* by an item in the list.
*
* The function should return 0 if the two objects are equivalent The
* function should return nonzero otherwise
*
* @param list
* the list containing the item to remove
*
* @param obj
* the object with which to compare each item
*
* @param compare
* the comparison function, passed obj and the obj member
* of each item, to return 0 if item should be removed
*
* @param removed
* RETURN: the removed item, or NULL if none was found
*
* @return the first element of the resulting list
*/
dlist_t *
void *obj,
int (compare)(void *, void *),
{
return (list);
}
return (list);
}
return (dlist_remove(item));
}
/*
* Remove an item from its list. Return the resulting list.
*
* @param item
* the item to remove, with prev and next pointers
* set to NULL
*
* @return the first element of the resulting list
*/
dlist_t *
{
}
}
/* Find head of list */
}
return (head);
}
/*
* append item to list, either beginning or end
*/
dlist_t *
{
} else if (attail) {
/* append to end */
} else {
/* insert at begining */
}
return (head);
}
/*
* Create a dlist_t element for the given object and append to list.
*
* @param object
* the obj member of the dlist_t element to be created
*
* @param list
* the list to which to append the new dlist_t element
*
* @param attail
* whether to append at the beginning (AT_HEAD) or end
* (AT_TAIL) of the list
*
* @return 0
* if successful
*
* @return ENOMEM
* if a dlist_t could not be allocated
*/
int
void *object,
{
return (ENOMEM);
}
return (0);
}
/*
* Appends list2 to the end of list1.
*
* Returns the resulting list.
*/
dlist_t *
{
return (list2);
}
/* Find last element of list1 */
}
return (list1);
}
/*
* compute number of items in list
*/
int
{
int length = 0;
++length;
return (length);
}
/*
* Allocate a new dlist_t structure and initialize the opaque object
* pointer the input object.
*
* @return A new dlist_t structure for the given object, or NULL
* if the memory could not be allocated.
*/
dlist_t *
void *obj)
{
}
return (item);
}
/*
* Traverse the list pointed to by head and free each
* list node. If freefunc is non-NULL, call freefunc
* for each node's object.
*/
void
void (freefunc(void *)))
{
}
}
}
/*
* Order the given list such that the number of similar elements
* adjacent to each other are minimized.
*
* The algorithm is:
*
* 1. Sort similar items into categories. Two elements are considered
* similar if the given compare function returns 0.
*
* 2. Create a new list by iterating through each category and
* selecting an element from the category with the most elements.
* Avoid choosing an element from the last category chosen.
*
* @param list
* the list to order
*
* @param compare
* the comparison function, passed the obj members
* of two items, to return 0 if the items can be
* considered similar
*
* @return the first element of the resulting list
*/
dlist_t *
int(compare)(void *, void *))
{
int ncategories = 0;
int max_elements;
int lastcat;
/*
* First, sort like items into categories, according to
* the passed-in compare function
*/
/* Remove this item from the list */
/* Create new category */
/* Add like items to same category */
/* Add removed item to category */
}
}
/*
* Next, create a new list, minimizing the number of adjacent
* elements from the same category
*/
lastcat = -1;
do {
int i;
int curcat;
/*
* Find the category with the most elements, other than
* the last category chosen
*/
max_elements = 0;
for (i = 0; i < ncategories; i++) {
int nelements;
if (i == lastcat) {
continue;
}
if (nelements > max_elements) {
curcat = i;
}
}
/* If no elements were found, use the last category chosen */
if (max_elements == 0 && lastcat >= 0) {
}
/* Was a category with elements found? */
if (max_elements != 0) {
/* Remove first element of chosen category */
/* Add removed element to resulting list */
}
} while (max_elements != 0);
return (list);
}