2 * ausearch-int.c - Minimal linked list library for integers
3 * Copyright (c) 2005,2008 Red Hat Inc., Durham, North Carolina.
6 * This software may be freely redistributed and/or modified under the
7 * terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2, or (at your option) any
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Steve Grubb <sgrubb@redhat.com>
27 #include "ausearch-int.h"
29 void ilist_create(ilist *l)
36 int_node *ilist_next(ilist *l)
40 l->cur = l->cur->next;
44 void ilist_append(ilist *l, int num, unsigned int hits, int aux)
48 newnode = malloc(sizeof(int_node));
55 // if we are at top, fix this up
58 else // Otherwise add pointer to newnode
59 l->cur->next = newnode;
61 // make newnode current
66 void ilist_clear(ilist* l)
69 register int_node* current;
76 nextnode=current->next;
85 int ilist_add_if_uniq(ilist *l, int num, int aux)
87 register int_node *cur, *prev;
91 if (cur->num == num) {
94 } else if (num > cur->num) {
100 // Insert so list is from low to high
101 if (cur == l->head) {
106 ilist_append(l, num, 1, aux);
118 /* No matches, append to the end */
119 ilist_append(l, num, 1, aux);
123 void ilist_sort_by_hits(ilist *l)
125 register int_node* cur, *prev = NULL;
132 /* Make sure l->cur points to end */
133 if (l->cur->next != NULL) {
140 while (cur && cur->next) {
141 /* If the next node is bigger */
142 if (cur->hits < cur->next->hits) {
147 prev->next = cur->next;
152 ilist_append(l, cur->num, cur->hits, cur->aux1);