2 * Copyright (c) 2006 Teodor Sigaev <teodor@sigaev.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 dumpGList(GList *l, char *str) {
45 printf("%s: GLIST_LENGTH(%d)\n", str, GLIST_LENGTH(l));
47 printf("\t%d\t%s\n", i++, (char*)GLCELL_DATA(c));
57 sprintf(buf,":%d:",i);
58 l = GListPush(l, tstrdup(buf));
61 l->cmpFunc = (GListCellComparator)strcmp;
62 l->freeFunc = (GListDataFreeFunc)tfree;
73 sprintf(buf,":%d:",i);
74 l = GListUnshift(l, tstrdup(buf));
77 l->cmpFunc = (GListCellComparator)strcmp;
78 l->freeFunc = (GListDataFreeFunc)tfree;
84 main(int argn, char *argv[]) {
88 dumpGList(fillF(), "Forward");
89 dumpGList(fillB(), "Backward");
91 dumpGList(GListTruncate(fillF(), 3), "Truncate");
92 dumpGList(GListConcat(fillF(), fillB()), "Concat");
93 dumpGList(GListDifference(fillF(), fillB()), "Difference");
94 dumpGList(GListUnion(fillF(), fillB()), "Union");
95 dumpGList(GListIntersect(fillF(), fillB()), "Intersect");
97 dumpGList(GListSort(fillB()), "Sort");
98 dumpGList(GListUniq(GListSort(GListConcat(fillF(), fillB()))), "Sort + Uniq + Concat");
101 c = GListFind(l,":10:");
102 printf("Find: %s\n", (char*)GLCELL_DATA(c));
103 dumpGList(GListInsert(l,c,"|11|"),"Insert");
104 dumpGList(GListDelete(l,c),"Delete :10:");
105 printf("Get #5: %s\n", (char*)GLCELL_DATA(GListGet(l,5)));
106 printf("Backward scan:\n");
107 GListForeachBack(c,l)
108 printf("\t%s\n", (char*)GLCELL_DATA(c));
112 while( (c=GListShift(l))!=NULL )
113 printf("\t%s\n", (char*)GLCELL_DATA(c));
117 while( (c=GListPop(l))!=NULL )
118 printf("\t%s\n", (char*)GLCELL_DATA(c));