高效的 C 语言列表实现 SimCList 1.6 发布
openkk 13年前
<p>SimCList 是一个用来处理列表(List)的的高效C库。内置很多基于列表的算法,例如排序、查找、随机处理等等。</p> <p>SimCList 1.6 提供了 Windows 下的兼容性,修复了一些函数的bug和文档的完善,修改了 list dump 的格式。</p> <p>下面是一段使用SimCList的示例代码:</p> <pre class="brush:cpp; toolbar: true; auto-links: false;">#include <stdio.h> #include <simclist.h> /* use the SimCList library */ int main() { list_t mylist; /* declare a list */ int userval; list_init(& mylist); /* initialize the list */ printf("Insert your number: "); scanf("%d", & userval); list_append(& mylist, & userval); /* add an element to the list */ printf("The list now holds %u elements.\n", \ list_size(& mylist)); /* get the size of the list */ printf("Your number was: %d\n", \ * (int*)list_get_at(& mylist, 0)); /* extract the first element of the list */ list_destroy(&mylist); return 0; }</pre>项目地址: <a href="/misc/goto?guid=4958194009782704545" target="_blank">http://mij.oltrelinux.com/devel/simclist/</a> <br /> <h2>The SimCList API</h2> <p>SimCList API is good because: </p> <ul> <li>it is simple, yet powerful</li> <li>it makes elegant and consistent use of information hiding</li> <li>it abstracts the actual data type to store</li> <li>it is fairly <q>total</q></li> </ul> <p>The library itself is very performant and makes a good compromise between performance in terms of time and space: </p> <ul> <li>insertion is O(n) [typically n/8]</li> <li>extraction and deletion are O(n) [typically n/8]</li> <li>iteration is O(1)</li> <li>sorting is always O(n logn), without worst case</li> </ul> <p></p>