GithubHelp home page GithubHelp logo

eastriverlee / array.h Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 702 KB

a lightweight dynamic (and generic) array type C is missing.

C 100.00%
array c macro meta-programming programming-language

array.h's Introduction

array.h

a lightweight dynamic (and generic) array type C is missing.

OVERVIEW

This is not a linked list but a dynamic array. Meaning that their elements are just next to each other.
Although removing element in the middle is expensive for this type, every time its capacity hits the limit, realloc occurs for the two times of the last capacity,

so tasks such as keep adding items, overwriting, removing the last element, slicing... are pretty cheap.

USAGE

example usage

I'd have totally freed this [word]

hello world and bye world

I'd have totally freed this [world]
I'd have totally freed this [bye]
I'd have totally freed this [and]
I'd have totally freed this [world]
I'd have totally freed this [hello]

Being a smart ass, I decided that declare_array(typename) macro to declare ItypenameI struct type that totally looks like [typename].

  1. use declare_array(typename) globally to make array type of typename.
  2. declare a ItypenameI variable.
  3. use II__init(variable, elementwise_cleanup, ...) to initialize an array.
  4. profit.

If you don't like two underscores (you have every right to be angry about it, but I have my own reasons), or the naming itself, please do change it, instead of swallowing it.

ADVANCED

Use this with defer.h to make the world better place, where the sun is shining, lollipops are singing, rainbows are giggling... and arrays are freeing themselves.

array.h's People

Contributors

eastriverlee avatar

Stargazers

 avatar

Watchers

 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.