OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ordinal.h
Go to the documentation of this file.
1 /* $Id: ordinal.h 346474 2009-11-14 10:18:58Z ssiano $
2  *
3  * ordinal.h - Ordinal assignment definitions
4  *
5  * Dave Katz, March 2008
6  *
7  * Copyright (c) 2008, Juniper Networks, Inc.
8  * All rights reserved.
9  */
10 
11 /*
12  * Overview
13  *
14  * This module hands out ordinals from a dense ordinal space. Two
15  * options are available--the ordinals can be as compact as possible,
16  * with a cost in CPU time, or the ordinals may be less than optimally
17  * compact but with a significant improvement in performance when the
18  * number of ordinals is large.
19  *
20  * If the compact option is chosen, the ordinals are guaranteed to be
21  * as compact as possible, and the lowest ordinal available will be
22  * provided to the next caller.
23  *
24  * If the compact option is not chosen, the ordinals delivered may have
25  * "holes" in the space if ordinals are repeatedly allocated and then
26  * freed.
27  *
28  * This routine relies on the bit vector code to do most of the work.
29  */
30 
31 
32 /*
33  *
34  * Calling Sequence
35  *
36  * ordinal_handle ord_create_context(ord_compact_option compact)
37  * Create an ordinal context. An ordinal context represents an ordinal
38  * space; the caller can have multiple ordinal spaces by creating multiple
39  * contexts. If "compact" is ORD_COMPACT, the ordinal space is as
40  * compact as possible. If the value is ORD_PERFORMANCE, the ordinal
41  * space may have holes in it if ordinals are repeatedly created and
42  * freed, but at a lower performance cost.
43  *
44  * ord_destroy_context(ordinal_handle handle)
45  * Destroy an ordinal context. This frees all memory associated with
46  * the ordinal context. Any assigned ordinals are freed.
47  *
48  * u_int32_t ord_get_ordinal(ordinal_handle handle)
49  * Returns the lowest-numbered free ordinal, or ORD_BAD_ORDINAL if out
50  * of memory or out of ordinal space.
51  *
52  * ord_free_ordinal(ordinal_handle handle, u_int32_t ordinal)
53  * Free a previously-assigned ordinal. Asserts if the ordinal wasn't
54  * previously assigned.
55  *
56  *
57  * A caller must first call ord_create_context() to create a context.
58  * Within the context, ord_get_ordinal() and ord_free_ordinal() can be
59  * used to allocate and free ordinal values. Finally,
60  * ord_destroy_context() must be called to free up the context to
61  * avoid memory leaks.
62  */
63 
64 #ifndef __ORDINAL_H__
65 #define __ORDINAL_H__
66 
67 /* Bad ordinal value. */
68 
69 #define ORD_BAD_ORDINAL BV_BAD_BITNUM
70 
71 
72 /*
73  * Opaque ordinal handle
74  */
75 typedef void *ordinal_handle;
76 
77 /*
78  * Ordinal number
79  */
81 
82 /*
83  * Ordinal compact option
84  */
86 
87 
88 /* Externs */
89 
91 extern void ord_destroy_context(ordinal_handle handle);
92 extern uint32_t ord_get_ordinal(ordinal_handle handle);
93 extern void ord_free_ordinal(ordinal_handle handle, uint32_t ordinal);
94 
95 #endif /* __ORDINAL_H__ */
ordinal_handle ord_create_context(ord_compact_option compact)
bv_bitnum_t ordinal_t
Definition: ordinal.h:80
void ord_destroy_context(ordinal_handle handle)
ord_compact_option
Definition: ordinal.h:85
uint32_t ord_get_ordinal(ordinal_handle handle)
void * ordinal_handle
Definition: ordinal.h:75
void ord_free_ordinal(ordinal_handle handle, uint32_t ordinal)
uint32_t bv_bitnum_t
Definition: bitvector.h:373