13434Sesaxe /* 23434Sesaxe * CDDL HEADER START 33434Sesaxe * 43434Sesaxe * The contents of this file are subject to the terms of the 53434Sesaxe * Common Development and Distribution License (the "License"). 63434Sesaxe * You may not use this file except in compliance with the License. 73434Sesaxe * 83434Sesaxe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93434Sesaxe * or http://www.opensolaris.org/os/licensing. 103434Sesaxe * See the License for the specific language governing permissions 113434Sesaxe * and limitations under the License. 123434Sesaxe * 133434Sesaxe * When distributing Covered Code, include this CDDL HEADER in each 143434Sesaxe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153434Sesaxe * If applicable, add the following below this CDDL HEADER, with the 163434Sesaxe * fields enclosed by brackets "[]" replaced with your own identifying 173434Sesaxe * information: Portions Copyright [yyyy] [name of copyright owner] 183434Sesaxe * 193434Sesaxe * CDDL HEADER END 203434Sesaxe */ 213434Sesaxe /* 228906SEric.Saxe@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 233434Sesaxe * Use is subject to license terms. 243434Sesaxe */ 253434Sesaxe 263434Sesaxe #ifndef _GROUP_H 273434Sesaxe #define _GROUP_H 283434Sesaxe 293434Sesaxe /* 303434Sesaxe * Group Abstraction 313434Sesaxe */ 323434Sesaxe 333434Sesaxe #ifdef __cplusplus 343434Sesaxe extern "C" { 353434Sesaxe #endif 363434Sesaxe 373434Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER)) 383434Sesaxe #include <sys/types.h> 393434Sesaxe 403434Sesaxe #define GRP_RESIZE 0x1 /* Resize group capacity if needed */ 413434Sesaxe #define GRP_NORESIZE 0x2 /* Do not resize group capacity; may fail */ 423434Sesaxe 433434Sesaxe /* 443434Sesaxe * group structure 453434Sesaxe */ 463434Sesaxe typedef struct group { 473434Sesaxe uint_t grp_size; /* # of elements */ 483434Sesaxe uint_t grp_capacity; /* current group capacity */ 493434Sesaxe void **grp_set; /* element vector */ 503434Sesaxe } group_t; 513434Sesaxe 523434Sesaxe typedef uint_t group_iter_t; 533434Sesaxe 543434Sesaxe 553434Sesaxe /* 563434Sesaxe * Return the number of elements in the group 573434Sesaxe */ 583434Sesaxe #define GROUP_SIZE(grp) ((grp)->grp_size) 593434Sesaxe 603434Sesaxe /* 613434Sesaxe * Access the element at the specified group index 623434Sesaxe */ 633434Sesaxe #define GROUP_ACCESS(grp, index) ((grp)->grp_set[index]) 643434Sesaxe 653434Sesaxe /* 663434Sesaxe * Group creation / destruction 673434Sesaxe */ 683434Sesaxe void group_create(group_t *); 693434Sesaxe void group_destroy(group_t *); 703434Sesaxe 713434Sesaxe /* 723434Sesaxe * Expand a group's holding capacity 733434Sesaxe */ 743434Sesaxe void group_expand(group_t *, uint_t); 753434Sesaxe 763434Sesaxe /* 773434Sesaxe * Group element iteration 783434Sesaxe */ 793434Sesaxe void group_iter_init(group_iter_t *); 808906SEric.Saxe@Sun.COM void *group_iterate(group_t *, group_iter_t *); 813434Sesaxe 823434Sesaxe /* 838906SEric.Saxe@Sun.COM * Add / remove an element (or elements) from the group 843434Sesaxe */ 853434Sesaxe int group_add(group_t *, void *, int); 863434Sesaxe int group_remove(group_t *, void *, int); 878906SEric.Saxe@Sun.COM void group_empty(group_t *); 883434Sesaxe 893434Sesaxe /* 903434Sesaxe * Add / remove / access an element at a specified index. 913434Sesaxe * The group must already have sufficient capacity to hold 923434Sesaxe * an element at the specified index. 933434Sesaxe */ 943434Sesaxe int group_add_at(group_t *, void *, uint_t); 953434Sesaxe void group_remove_at(group_t *, uint_t); 963434Sesaxe 978906SEric.Saxe@Sun.COM /* 988906SEric.Saxe@Sun.COM * Search for an element in a group. 998906SEric.Saxe@Sun.COM * Returns an index that may be used with the *_at() 1008906SEric.Saxe@Sun.COM * routines above to add or remove the element. 1018906SEric.Saxe@Sun.COM */ 1028906SEric.Saxe@Sun.COM uint_t group_find(group_t *, void *); 1038906SEric.Saxe@Sun.COM 104*11389SAlexander.Kolbasov@Sun.COM /* 105*11389SAlexander.Kolbasov@Sun.COM * Convert a group to a string with list of integers. 106*11389SAlexander.Kolbasov@Sun.COM * 107*11389SAlexander.Kolbasov@Sun.COM * The consecutive integer values are represented using x-y notation. 108*11389SAlexander.Kolbasov@Sun.COM * The resulting string looks like "1,2-5,8" 109*11389SAlexander.Kolbasov@Sun.COM * 110*11389SAlexander.Kolbasov@Sun.COM * The convert argument is used to map group elements to integer IDs. 111*11389SAlexander.Kolbasov@Sun.COM * The output buffer and its length are specfied in the arguments. 112*11389SAlexander.Kolbasov@Sun.COM */ 113*11389SAlexander.Kolbasov@Sun.COM extern char *group2intlist(group_t *, char *, size_t, int (convert)(void*)); 114*11389SAlexander.Kolbasov@Sun.COM 1153434Sesaxe #endif /* !_KERNEL && !_KMEMUSER */ 1163434Sesaxe 1173434Sesaxe #ifdef __cplusplus 1183434Sesaxe } 1193434Sesaxe #endif 1203434Sesaxe 1213434Sesaxe #endif /* _GROUP_H */ 122