summaryrefslogtreecommitdiff
path: root/src/lib/libssl/src/doc/stack.doc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/src/doc/stack.doc')
-rw-r--r--src/lib/libssl/src/doc/stack.doc96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/libssl/src/doc/stack.doc b/src/lib/libssl/src/doc/stack.doc
new file mode 100644
index 0000000000..7c20b1b664
--- /dev/null
+++ b/src/lib/libssl/src/doc/stack.doc
@@ -0,0 +1,96 @@
1The stack data structure is used to store an ordered list of objects.
2It is basically misnamed to call it a stack but it can function that way
3and that is what I originally used it for. Due to the way element
4pointers are kept in a malloc()ed array, the most efficient way to use this
5structure is to add and delete elements from the end via sk_pop() and
6sk_push(). If you wish to do 'lookups' sk_find() is quite efficient since
7it will sort the stack (if required) and then do a binary search to lookup
8the requested item. This sorting occurs automatically so just sk_push()
9elements on the stack and don't worry about the order. Do remember that if
10you do a sk_find(), the order of the elements will change.
11
12You should never need to 'touch' this structure directly.
13typedef struct stack_st
14 {
15 unsigned int num;
16 char **data;
17 int sorted;
18
19 unsigned int num_alloc;
20 int (*comp)();
21 } STACK;
22
23'num' holds the number of elements in the stack, 'data' is the array of
24elements. 'sorted' is 1 is the list has been sorted, 0 if not.
25
26num_alloc is the number of 'nodes' allocated in 'data'. When num becomes
27larger than num_alloc, data is realloced to a larger size.
28If 'comp' is set, it is a function that is used to compare 2 of the items
29in the stack. The function should return -1, 0 or 1, depending on the
30ordering.
31
32#define sk_num(sk) ((sk)->num)
33#define sk_value(sk,n) ((sk)->data[n])
34
35These 2 macros should be used to access the number of elements in the
36'stack' and to access a pointer to one of the values.
37
38STACK *sk_new(int (*c)());
39 This creates a new stack. If 'c', the comparison function, is not
40specified, the various functions that operate on a sorted 'stack' will not
41work (sk_find()). NULL is returned on failure.
42
43void sk_free(STACK *);
44 This function free()'s a stack structure. The elements in the
45stack will not be freed so one should 'pop' and free all elements from the
46stack before calling this function or call sk_pop_free() instead.
47
48void sk_pop_free(STACK *st; void (*func)());
49 This function calls 'func' for each element on the stack, passing
50the element as the argument. sk_free() is then called to free the 'stack'
51structure.
52
53int sk_insert(STACK *sk,char *data,int where);
54 This function inserts 'data' into stack 'sk' at location 'where'.
55If 'where' is larger that the number of elements in the stack, the element
56is put at the end. This function tends to be used by other 'stack'
57functions. Returns 0 on failure, otherwise the number of elements in the
58new stack.
59
60char *sk_delete(STACK *st,int loc);
61 Remove the item a location 'loc' from the stack and returns it.
62Returns NULL if the 'loc' is out of range.
63
64char *sk_delete_ptr(STACK *st, char *p);
65 If the data item pointed to by 'p' is in the stack, it is deleted
66from the stack and returned. NULL is returned if the element is not in the
67stack.
68
69int sk_find(STACK *st,char *data);
70 Returns the location that contains a value that is equal to
71the 'data' item. If the comparison function was not set, this function
72does a linear search. This function actually qsort()s the stack if it is not
73in order and then uses bsearch() to do the initial search. If the
74search fails,, -1 is returned. For mutliple items with the same
75value, the index of the first in the array is returned.
76
77int sk_push(STACK *st,char *data);
78 Append 'data' to the stack. 0 is returned if there is a failure
79(due to a malloc failure), else 1. This is
80sk_insert(st,data,sk_num(st));
81
82int sk_unshift(STACK *st,char *data);
83 Prepend 'data' to the front (location 0) of the stack. This is
84sk_insert(st,data,0);
85
86char *sk_shift(STACK *st);
87 Return and delete from the stack the first element in the stack.
88This is sk_delete(st,0);
89
90char *sk_pop(STACK *st);
91 Return and delete the last element on the stack. This is
92sk_delete(st,sk_num(sk)-1);
93
94void sk_zero(STACK *st);
95 Removes all items from the stack. It does not 'free'
96pointers but is a quick way to clear a 'stack of references'.