C Template Library

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • ctl

    The C Template Library

  • The performance of sort being exactly the same as the C++ implementation looked a bit suspicious to me at first. Notable that in the C++ performance test a function pointer is passed to std::sort in a similar way how the C library is used [1].

    This is probably a good way to check that the C library doesn't do worse in this case, but it's notable that C++ has potentially faster ways to do the sorting:

    1. Pass a function object (even a lambda that just wraps "compare")

    2. Don't pass a comparison at all for the "vector" case, as the default works there.

    Both of these methods have better chances for inlining the comparison within the sort implementation. For the function pointer case it would require constant propagation and possibly "cloning" to do the same, which is less likely for a complicated algorithm like sort.

    [1] https://github.com/glouw/ctl/blob/09f5e0a89d3fc621aff94290c4...

    edit: I wonder how ctl's vector sort compares to qsort, I expect it to be faster.

  • Klib

    A standalone and lightweight C library

  • These kinds of macro hacks are pretty widespread, aren't they? To me, klib and its khash hash table is the most well-known implementation, see: https://github.com/attractivechaos/klib

    And I've written similar things myself (hash table and vectors).

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • ctl

    C Template Library (by Equationist)

  • I recall a few years back doing something like this implementing a binary heap just as a hobby project (https://github.com/Equationist/ctl/blob/master/pqueue.h). I was curious to see how unoptimized it was vis a vis the STL, and ran compiled equivalent test code for both my priority queue and the STL's C++ implementation, with just integers. I was kind of shocked to find that my implementation was like 30% faster when both were compiled at -O3 levels. Seeing this backport I guess there isn't anything fancy in the STL implementations, so it's less surprising that my naive implementation could be just as fast (or happen to be faster).

  • src

    Read-only git conversion of OpenBSD's official CVS src repository. Pull requests not accepted - send diffs to the tech@ mailing list.

  • You're welcome. And you might like to see: https://github.com/openbsd/src/blob/master/sys/sys/queue.h

  • nlutils

    Nitrogen Logic C Utility Library

  • This is cool! I've seen this C-with-templates used in the past with ".X" headers but haven't used the technique myself. Having something based on STL might help people to center on one library instead of constantly reinventing collections in C (which I've also done for some structures, and open sourced though I don't recommend using it: https://github.com/nitrogenlogic/nlutils).

  • frr

    The FRRouting Protocol Suite

  • Shameless plug:

    http://docs.frrouting.org/projects/dev-guide/en/latest/lists...

    https://github.com/FRRouting/frr/blob/master/lib/typesafe.h

    Differs in a bunch of design decisions. Memory management for items is strictly out of scope, though some of the structures use malloc/free for their own purposes (e.g. heap). Much more focus on sorted/hashed structures, explicitly differentiating for [not] having duplicate items that compare equal. Also, atomic/lock-free versions. Uses macros instead of #including files multiple times.

    But fun to see someone else's go at the same idea :)

  • notes

    Assorted notes (by apankrat)

  • Nice, very nice. All of it. Long live C.

    Being stuck with C++ I did something in reverse - ported C-style ("intrusive") containers to ++, making them a bit safer to use, but keeping the syntax nearly the same.

    https://github.com/apankrat/notes/tree/master/intrusive-cont...

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
  • pottery

    Pottery - A container and algorithm template library in C (by ludocode)

  • Might as well plug mine too:

    https://github.com/ludocode/pottery

    I'm not really sure what makes a project take off on HN. I posted mine here a couple weeks ago and got one single upvote :(. I'm glad to see the new style of #include templates getting more attention though. I think in general it's the right way to do templates in C.

  • nusort

    Japanese direct-to-kanji input system with 2-key codes

  • Did you consider using more traditional macros like VEC_ADD which works for all types rather than generating e.g. vec__add? The latter approach doesn't work with cscope and ctags, which is a pretty big drawback in my book (I like it when my super trivial IDE configuration works, which is only possible with C).

    See the comment and following 4 macros for how this would work with a (write-only, not growable) hashmap:

    https://github.com/matvore/nusort/blob/master/src/util.h#L16...

  • sort

    Sorting routine implementations in "template" C (by swenson)

  • FWIW, for sorting in a template-like C package I use https://github.com/swenson/sort/ .

  • ctl

    My variant of the C Template Library (by rurban)

  • I didn't like the names at all, and also it shouldn't be in the main namespace, but under ctl/

    https://github.com/rurban/ctl

    In work are map, forward_list, unordered_set, and utf-8 support for strings and identifiers, with its stricter rules.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Uthash – C macros for hash tables and more

    4 projects | news.ycombinator.com | 25 Mar 2022
  • Tree.h in OpenBSD: dependency-free intrusive binary tree (2002)

    6 projects | news.ycombinator.com | 8 Apr 2021
  • Software Engineering Workflow

    6 projects | dev.to | 8 Apr 2024
  • Ravi is a dialect of Lua, with JIT and AOT compilers

    7 projects | news.ycombinator.com | 18 Mar 2024
  • STB: Single-file public domain libraries for C/C++

    4 projects | news.ycombinator.com | 6 Jan 2024