Giter Club home page Giter Club logo

clinq's Introduction

CLINQ

This is a very basic proof-of-concept for adding LINQ-like list features to C. It started as part of another project, and I don't even know if it's practical for use elsewhere, but it's kind of cool.

Operations

All of these are modeled after the equivalent C#/LINQ operation and operate on a linked list:

struct node {
	struct node* next;
	void* record;
};

Aggregate

void ll_aggregate(struct node* head, void (*fn)(void* accum, void* val), void* accum);

Aggregate an operation over an entire list with an initial value and an accumulator.

  • head: Pointer to the first node in a linked list
  • fn: Pointer to a function accepting two arguments (an accumulator and a record) that modifies the accumulated value to include the record's information
  • accum: Pointer to an accumulator. May optionally be initialized with an initial value. Result is stored at accum.

Each

void ll_each(struct node* head, void (*fn)(unsigned int, void*));

Perform an operation for each record in a linked list.

  • head: Pointer to the first node in a linked list
  • fn: Pointer to a function accepting two arguments (index of the element in the list and a pointer to the record stored there)

Single

void* ll_single(struct node* head);

Get the record stored in the first and only node of a linked list. Errors (returns NULL) if the list does not have exactly one node.

  • head: Pointer to the first node in a linked list
  • returns: Pointer to the record stored in the first and only element of the list, or NULL if length is not exactly 1.

Where

struct node* ll_where(struct node* head, bool (*fn)(unsigned int, void*, void*), void* term);

Create a new linked list of nodes containing only the nodes of a first linked list whose contents satisfy a certain condition.

  • head: Pointer to the first node in a linked list
  • fn: Pointer to a function accepting three arguments (this index of the node in the list, a pointer to the record in the node, and a pointer to the search term to test against) that returns true whenever the record matches the search term
  • term: Pointer to the search term to pass to fn
  • returns: New linked list containing only those elements in the original for which fn returned true

clinq's People

Contributors

btmills avatar

Watchers

 avatar  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.