|
|
|
|
|
by ambrop7
4755 days ago
|
|
Intrusive data structures are indeed more powerful. I made my own instrusive AVL-tree which can be found here [1] and an example here [2]. There's also the extra feature that the concept of a "link" is abstracted, so you can for example build a compressed AVL-tree inside an array using array indices instead of pointers, which don't break when the array is reallocated. It's also built in a different way than this usually done (macros), that is, a header file is included which redefines some identifiers, and the actual code of the functions is not inside macros, hence, easier to read. About strings, I firmly believe that C's zero-terminated strings should be avoided and only used when necessary to communicate with existing code. They're really not simple and fast. You can't take a null-terminated string and extract a null-terminated sub-string without modifying the original - which is very often needed during various kinds of parsing. Also, null-terminated strings are unable to represent the zero byte, so in general, for example, you can't use them to store the contents of an arbitrary file, and if you do use them for purposes where null bytes can appear, you have to be careful and handle errors where nulls would implicitly truncate your string. Just use (pointer, length) strings instead. It'll save you a whole bunch of trouble you may not see coming. [1] https://code.google.com/p/badvpn/source/browse/#svn%2Ftrunk%... (CAvl_) [2] https://code.google.com/p/badvpn/source/browse/#svn%2Ftrunk%... (cavl_test_) |
|