CC VS SDS

Compare CC vs SDS and see what are their differences.

CC

A small, usability-oriented generic container library. (by JacksonAllan)

SDS

Simple Dynamic Strings library for C (by antirez)
Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
CC SDS
21 48
100 4,787
- -
5.1 0.0
14 days ago 7 months ago
C C
MIT License BSD 2-clause "Simplified" License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

CC

Posts with mentions or reviews of CC. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-12-09.
  • preprocessor stuff - compile time pasting into other files
    2 projects | /r/C_Programming | 9 Dec 2023
    With extendible macros, you could achieve the following:
  • Factor is faster than Zig
    11 projects | news.ycombinator.com | 10 Nov 2023
    In my example the table stores the hash codes themselves instead of the keys (because the hash function is invertible)

    Oh, I see, right. If determining the home bucket is trivial, then the back-shifting method is great. The issue is just that it’s not as much of a general-purpose solution as it may initially seem.

    “With a different algorithm (Robin Hood or bidirectional linear probing), the load factor can be kept well over 90% with good performance, as the benchmarks in the same repo demonstrate.”

    I’ve seen the 90% claim made several times in literature on Robin Hood hash tables. In my experience, the claim is a bit exaggerated, although I suppose it depends on what our idea of “good performance” is. See these benchmarks, which again go up to a maximum load factor of 0.95 (Although boost and Absl forcibly grow/rehash at 0.85-0.9):

    https://strong-starlight-4ea0ed.netlify.app/

    Tsl, Martinus, and CC are all Robin Hood tables (https://github.com/Tessil/robin-map, https://github.com/martinus/robin-hood-hashing, and https://github.com/JacksonAllan/CC, respectively). Absl and Boost are the well-known SIMD-based hash tables. Khash (https://github.com/attractivechaos/klib/blob/master/khash.h) is, I think, an ordinary open-addressing table using quadratic probing. Fastmap is a new, yet-to-be-published design that is fundamentally similar to bytell (https://www.youtube.com/watch?v=M2fKMP47slQ) but also incorporates some aspects of the aforementioned SIMD maps (it caches a 4-bit fragment of the hash code to avoid most key comparisons).

    As you can see, all the Robin Hood maps spike upwards dramatically as the load factor gets high, becoming as much as 5-6 times slower at 0.95 vs 0.5 in one of the benchmarks (uint64_t key, 256-bit struct value: Total time to erase 1000 existing elements with N elements in map). Only the SIMD maps (with Boost being the better performer) and Fastmap appear mostly immune to load factor in all benchmarks, although the SIMD maps do - I believe - use tombstones for deletion.

    I’ve only read briefly about bi-directional linear probing – never experimented with it.

  • If this isn't the perfect data structure, why?
    3 projects | /r/C_Programming | 22 Oct 2023
    From your other comments, it seems like your knowledge of hash tables might be limited to closed-addressing/separate-chaining hash tables. The current frontrunners in high-performance, memory-efficient hash table design all use some form of open addressing, largely to avoid pointer chasing and limit cache misses. In this regard, you want to check our SSE-powered hash tables (such as Abseil, Boost, and Folly/F14), Robin Hood hash tables (such as Martinus and Tessil), or Skarupke (I've recently had a lot of success with a similar design that I will publish here soon and is destined to replace my own Robin Hood hash tables). Also check out existing research/benchmarks here and here. But we a little bit wary of any benchmarks you look at or perform because there are a lot of factors that influence the result (e.g. benchmarking hash tables at a maximum load factor of 0.5 will produce wildly different result to benchmarking them at a load factor of 0.95, just as benchmarking them with integer keys-value pairs will produce different results to benchmarking them with 256-byte key-value pairs). And you need to familiarize yourself with open addressing and different probing strategies (e.g. linear, quadratic) first.
  • Convenient Containers: A usability-oriented generic container library
    1 project | news.ycombinator.com | 30 Jul 2023
  • [Noob Question] How do C programmers get around not having hash maps?
    3 projects | /r/C_Programming | 22 Jun 2023
    CC (Full disclosure: I authored this one)
  • New C features in GCC 13
    3 projects | /r/C_Programming | 4 May 2023
    If you're using C23 or have typeof (so GCC or Clang), then yet another approach is to define a type that aliases the specified type if it is unique or otherwise becomes a "dummy" type. Here's what that looks like in CC:
  • Convenient Containers v1.0.3: Better compile speed, faster maps and sets
    4 projects | /r/C_Programming | 3 May 2023
    I’d like to share version 1.0.3 of Convenient Containers (CC), my generic container library. The library was previously discussed here and here. As explained elsewhere,
  • Popular Data Structure Libraries in C ?
    13 projects | /r/C_Programming | 22 Mar 2023
    Convenient Containers (CC) - I'm the author of this one.
  • So what's the best data structures and algorithms library for C?
    8 projects | /r/C_Programming | 15 Mar 2023
    "Using macros" is a broad description that covers multiple paradigms. There are libraries that use macros in combination with typed pointers and functions that take void* parameters to provide some degree of API genericity and type safety at the same time (e.g. stb_ds and, as you mentioned, my own CC). There are libraries that use macros (or #include directives) to manually instantiate templates (e.g. STC, M*LIB, and Pottery). And then there are libraries that are implemented entirely or almost entirely as macros (e.g. uthash).
  • How do you deal with the extra verbosity of C?
    3 projects | /r/C_Programming | 14 Mar 2023
    Shameless plug: Take a look a my library Convenient Containers, which solves this exact problem within the (narrow) domain of data structures.

SDS

Posts with mentions or reviews of SDS. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-05-06.
  • Strlcpy and strlcat added to glibc 2.38
    1 project | news.ycombinator.com | 18 Jul 2023
    Let me reframe this. What we're saying to do is stop using C string manipulation such as strcat, strcpy, etc. Particularly, I'm saying simply don't use C-style null terminated strings until you actually go to call a C ABI interface where it is necessary.

    The argument against this is that you might call something that already does this. Yes, sure, that IS true, but what this betrays is the fact that you have to deal with that regardless of whether or not you add additional error-prone C string manipulation code on top of having to worry about memory ownership, mutation, etc. when passing blobs of memory to "untrusted" APIs.

    It's not about passing the buck. Passing a blob of memory to an API that might do horrible things not defined by an API contract is not safe if you do strcat to construct the string or you clone it out of an std::string or you marshal it from Go or Rust. It's about not creating a bigger mess than you already have.

    Okay fine, but what if someone hates C++ and Rust and Go and Zig? No problem. There are a slew of options for C that can all handle safer, less error-prone string manipulation, including interoperability with null-terminated C strings. Like this one used in Redis:

    https://github.com/antirez/sds

    And on top of everything else, it's quite ergonomic, so it seems silly to not consider it.

    This entire line of thinking deeply reminds me of Technology Connection's video The LED Traffic Light and the Danger of "But Sometimes!".

    https://youtube.com/watch?v=GiYO1TObNz8

    I think hypothetically you can construct some scenarios where not using C strings for string manipulation requires more care, but justifying error prone C string manipulation with "well, I might call something that might do something unreasonable" as if that isn't still your problem regardless of how you get there makes zero sense to me.

    And besides, these hypothetical incorrect APIs would crash horrifically on the DS9K anyways.

  • Safest way to copy a string?
    3 projects | /r/C_Programming | 6 May 2023
    Even better, use a string handling library. Personally I am a big fan of (sds)[https://github.com/antirez/sds] from the Redis creator. It's not even a dependancy you can just copy the .c and .h to your project.
  • New C features in GCC 13
    3 projects | /r/C_Programming | 4 May 2023
    One nice application is length-prefixed string literals to complement dynamic string libraries:
  • Strlcpy and Strlcat – Consistent, Safe, String Copy and Concatenation (1999) [pdf]
    1 project | news.ycombinator.com | 25 Apr 2023
    The better answer would be to add data types like SDS[0] to the standard library, and use them as ADTs (Abstract Data Types) [1].

    Unfortunely WG14 has proven in 30 years of existence, that it isn't something that they care to fix, and while 3rd party solutions exist, without vocabulary types on the stardard library adoption will never take off.

    [0] - https://github.com/antirez/sds

    [1] - https://en.wikipedia.org/wiki/Abstract_data_type

  • C Strings and my slow descent to madness
    3 projects | news.ycombinator.com | 6 Apr 2023
    With the woes of string.h being known, why not just use an alternative like https://github.com/antirez/sds ?

    I’ve also been having a blast with C because writing C feels like being a god! But the biggest thing that I like about C is that the world is sort of written on it!

    Just yesterday I needed to parse a JSON… found a bunch of libraries that do that and just picked one that I liked the API.

  • How can i know for sure that i am allocating enough memory?
    1 project | /r/C_Programming | 15 Mar 2023
    Please note that the discussion started with requirement for no dynamic allocation in critical code what virtually eliminates std::string. I agree that std::string code tends to be simpler but the main reason is that the standard C library sucks on strings. There are better alternatives like sds but they are ... not standard.
  • str_header.h - A single header C string library
    1 project | /r/C_Programming | 28 Jan 2023
    Another day, another post about a writing a bespoke string lib instead of using SDS
  • C_dictionary: A simple dynamically typed and sized hashmap in C - feedback welcome
    10 projects | /r/C_Programming | 23 Jan 2023
    d) everything being a macro seems overkill for me (and possibly dangerous, see b)). Maybe implement more as static inline functions, see the sds header: https://github.com/antirez/sds/blob/master/sds.h (which does a similar thing with the header struct).
  • Updated book to learn C
    2 projects | /r/C_Programming | 15 Jan 2023
    For example, you can use the C language with sds strings (see https://github.com/antirez/sds) if you want to have an easier time with string formatting and don't want to worry about using the famously unsafe string.h functions correctly. You'll still program in ISO C, but just not in the standard library. The same applies to pretty much all parts of the standard library, the only part unsurpassed is pretty much just printf and the math headers (math.h, fenv.h, tgmath.h, complex.h) imo, and the occasional call to exit. A good place to look for libraries if you want to go that route is the awesome-c collection: https://github.com/oz123/awesome-c
  • Convenient Containers: A usability-oriented generic container library
    4 projects | /r/C_Programming | 26 Dec 2022
    One way around this problem is to declare the container as a pointer to the element type and then store the container’s metadata, alongside its elements, in the heap block to which the pointer points. This approach is already used for dynamic arrays in several container libraries, most notably stb_ds and sds. They place the metadata before the elements and provide the user with a pointer to the elements themselves (this has the nice effect that users can use the [] operator to access elements).

What are some alternatives?

When comparing CC and SDS you can also consider the following projects:

rust-bindgen - Automatically generates Rust FFI bindings to C (and some C++) libraries.

Better String - The Better String Library

mlib - Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).

Experimental Boost.MSM-lite - Boost.SML (formerly called Boost.MSM-lite)

stent - Completely avoid dangling pointers in C.

libcpuid - a small C library for x86 CPU detection and feature extraction

Generic-Data-Structures - A set of Data Structures for the C programming language

ZXing - ZXing ("Zebra Crossing") barcode scanning library for Java, Android

stb - stb single-file public domain libraries for C/C++

safestringlib

Klib - A standalone and lightweight C library