Comments (1)
I’m hesitant to introduce any new containers (beside the planned null-terminated strings) for a few reasons:
-
CC is not only a single-header library but also a library that, for best performance, needs to be compiled once per translation unit that uses it (or else be compiled with link-time optimization enabled). That’s because we want the compiler to inline as many of the container functions as possible so that it can optimize all the calls to
memcpy
and comparison and hash functions, just like it would if there were separate, specialized functions for every container/key/element-type combination. This approach is the reason that every function in CC is declared asstatic inline
and that CC, unlike other single-header libraries, doesn’t ask the user to define something likeCC_IMPLEMENTATION
in one translation unit. However, it also means that there’s a strong incentive to keep the library lean in order to limit its impact on build times and limit code duplication (for any functions that don't get inlined) inside the resulting executable. Even before the addition of strings, the header is already 291 KB (although about 40% consists of documentation and comments, and a lot of whitespace is used to format macros nicely). -
The container lineup – vectors, linked lists, maps and sets (i.e. hash tables), ordered maps and ordered sets (i.e. binary search trees), and strings – was planned since the beginning on the basis that it constitutes a minimal set of containers that would cover most common needs. My thinking was always that for more specific or esoteric needs, users should turn to a specialized library. For example, CC's pair of associative containers—namely one high-performance unordered container without iterator stability (its hash table) and one lower-performance ordered container with iterator stability (its red-black tree)—should hopefully serve most users' needs, but a user who needs the specific combination of high performance, order, and no iterator stability should perhaps look elsewhere for a standalone b-tree library.
The point I’m making here is that the fact that a container could be incorporated into CC doesn’t necessarily mean that it should be, both from a practical and technical perspective (i.e. limiting build times and potential code duplication) and from the perspective of design-philosophy (i.e. keeping the scope limited and focused on common needs).
With all that said, I would consider adding another container if I thought it catered to a common use case. In this regard, I don’t really understand the tree structure you’re proposing. How would it differ from the red-black trees that CC already includes? Is there an existing implementation or library that I can look at to get a clearer idea?
On a side note, I think the easiest way to add a new container to CC is to implement it separately first and then worry about integrating it into the library. CC has quite a few unusual implementation details that can be distracting when you’re trying to lock in the logic of the actual data structure. That's how I went about developing both CC's hash table and its red-black tree.
from cc.
Related Issues (9)
- Virus warning on Windows HOT 1
- Memory usage for each instance HOT 4
- Custom maximum load factors for maps and sets not taking effect (now fixed)
- Incomplete type analysis? HOT 2
- A segmentation fault occurs when a map is cleared HOT 2
- Support for MSVC 19.39 (or later) HOT 8
- cc_insert() doesnt compile if compound literal doesnt wrapped up with extra braces. HOT 2
- Planned dynamic string API HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cc.