Tllist

Jul 20, 2023

C header file only implementation of a typed linked list

Most C implementations of linked list are untyped. That is, their data carriers are typically void *. This is error prone since your compiler will not be able to help you correct your mistakes oh, was it a pointer-to-a-pointer… I thought it was just a pointer….

tllist addresses this by using pre-processor macros to implement dynamic types, where the data carrier is typed to whatever you want; both primitive data types are supported as well as aggregated ones such as structs, enums and unions.

Being a double-linked list, most operations are constant in time including pushing and popping both to/from front and back.

The memory overhead is fairly small; each item carries, besides its data, a prev and next pointer i.e. a constant 16 byte overhead per item on 64-bit architectures.

The list itself has two head and tail pointers, plus a length variable typically 8 bytes on 64-bit architectures to make list length lookup constant in time.

Thus, assuming 64-bit pointers and a 64-bit size_t type, the total overhead is 38 + n2*8 bytes.



Checkout these related ports:
  • Zziplib - Library to provide transparent read access to zipped files
  • Zydis - Fast and lightweight x86/x86-64 disassembler library
  • Zycore-c - Support library with platform independent types, macros, etc for Zydis
  • Zthread - Platform-independent object-oriented C++ threading library
  • Zookeeper - Coordination Service for Distributed Applications
  • Zls - Zig LSP implementation + Zig Language Server
  • Zfp - High throughput library for compressed floating-point arrays
  • Zeal - Offline documentation browser
  • Zapcc - C++ caching compiler based on clang
  • Zanata-platform - Web-based translation platform
  • Zanata-cli - Zanata Java command line client
  • Z88dk - Complete Z80/Z180 development kit
  • Z80ex - ZiLOG Z80 CPU emulator library
  • Z80asm - Assembler for the Z80 microprocessor
  • Z80-asm - Z80 assembly code assembler and disassembler