Code Monkey home page Code Monkey logo

list's Introduction

BSD licensed generic linked list for C99, used in liblacewing and some other stuff.

Uses typeof and statement expressions which are GNU extensions, but will work with MSVC++ with a hack.

For a usage example, see test.c.

Features

  • "Object in list" rather than "list in object": the listed objects do not have to be aware of the list

  • The linked list logic (and internal representation) is separate from the macros

  • The list head does not require initialisation other than being cleared with null bytes

  • The macros are intuitive and do not require any unnecessary parameters. In particular, the list type does not need to be passed to each operation.

  • The loop macros expand to the head of a for loop, so the syntax for using them isn't buggered up. This means that one can use break and continue normally.

List operations

 list(type, name)                 Declare a list
 list_push(list, value)           Push value to back
 list_push_front(list, value)     Push value to front
 list_pop(list)                   Pop and return value from back
 list_pop_front(list)             Pop and return value from front
 list_length(list)                Returns the list length
 list_remove(list, value)         Remove first occurrence of value from list
 list_clear(list)                 Clear the list (freeing all memory)

Element (pointer) operations

 list_elem_front(list)            Returns element at the front of list
 list_elem_back(list)             Returns element at the back of list
 list_elem_next(elem)             Returns element after elem
 list_elem_prev(elem)             Returns element before elem
 list_elem_remove(elem)           Remove element elem

Loops

 list_each(list, elem) { ... }

Loops through each list element, front to back. elem will be declared and set to the actual value of each element (not a pointer or iterator)

 list_each_r(list, elem) { ... }

Loops through each list element, back to front. elem will be declared and set to the actual value of each element (not a pointer or iterator)

 list_each_elem(list, elem) { ... }

Loops through each list element, front to back. elem will be declared and set to a pointer to each element.

 list_each_r_elem(list, elem) { ... }

Loops through each list element, back to front. elem will be declared and set to a pointer to each element.

list's People

Watchers

James Cloos avatar Naichuan Zhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.