gpointer
pointers, since an honest solution to this problem in C is possible only with the involvement of a preprocessor and will be a terrible mess of macros that is difficult to understand and debug, as demonstrated existing similar projects. That is, nothing similar in terms of harmony and convenience of STL containers for C ++ and collections of Java and Sharp can be built using standard C tools.Vector
(C ++ / Java analogues: std::vector
and java.util.ArrayList
).List
(the nearest C ++ / Java analogues are doubly linked lists: std::list
and java.util.LinkedList
).HashSet
hashes (C ++ / Java analogues: std::unordered_set
and java.util.HashSet
).HashMap
hash-based display (C ++ / Java analogues: std::unordered_map
and java.util.HashMap
). std::list std::list ).
, , . , , , copy-on-write .. , - , , , ..
AutoC , std::unordered_set ++.
(set), :
require "autoc" CodeBuilder::CModule.generate!("containers") do |m| m << DataStructBuilder::HashSet.new("IntSet", {:type=>"int"}) end
IntSet
:
... typedef struct IntSet IntSet; struct IntSet {...} ... void IntSetCtor(IntSet*); void IntSetDtor(IntSet*); void IntSetPut(IntSet*, int); ...
IntSet
:
#include <stdio.h> #include "containers_auto.h" int main(int argc, char** argv) { IntSet set; IntSetCtor(&set); IntSetPut(&set, 0); IntSetPut(&set, 1); IntSetPut(&set, 0); printf("size(set)=%d\n", IntSetSize(&set)); printf("contains(1)==%d\n", IntSetContains(&set, 1)); IntSetDtor(&set); return 0; }
; , , ( API ). , , .
, .
PS
.
std::list std::list ).
, , . , , , copy-on-write .. , - , , , ..
AutoC , std::unordered_set ++.
(set), :
require "autoc" CodeBuilder::CModule.generate!("containers") do |m| m << DataStructBuilder::HashSet.new("IntSet", {:type=>"int"}) end
IntSet
:
... typedef struct IntSet IntSet; struct IntSet {...} ... void IntSetCtor(IntSet*); void IntSetDtor(IntSet*); void IntSetPut(IntSet*, int); ...
IntSet
:
#include <stdio.h> #include "containers_auto.h" int main(int argc, char** argv) { IntSet set; IntSetCtor(&set); IntSetPut(&set, 0); IntSetPut(&set, 1); IntSetPut(&set, 0); printf("size(set)=%d\n", IntSetSize(&set)); printf("contains(1)==%d\n", IntSetContains(&set, 1)); IntSetDtor(&set); return 0; }
; , , ( API ). , , .
, .
PS
.
std::list std::list ).
, , . , , , copy-on-write .. , - , , , ..
AutoC , std::unordered_set ++.
(set), :
require "autoc" CodeBuilder::CModule.generate!("containers") do |m| m << DataStructBuilder::HashSet.new("IntSet", {:type=>"int"}) end
IntSet
:
... typedef struct IntSet IntSet; struct IntSet {...} ... void IntSetCtor(IntSet*); void IntSetDtor(IntSet*); void IntSetPut(IntSet*, int); ...
IntSet
:
#include <stdio.h> #include "containers_auto.h" int main(int argc, char** argv) { IntSet set; IntSetCtor(&set); IntSetPut(&set, 0); IntSetPut(&set, 1); IntSetPut(&set, 0); printf("size(set)=%d\n", IntSetSize(&set)); printf("contains(1)==%d\n", IntSetContains(&set, 1)); IntSetDtor(&set); return 0; }
; , , ( API ). , , .
, .
PS
.
std::list std::list ).
, , . , , , copy-on-write .. , - , , , ..
AutoC , std::unordered_set ++.
(set), :
require "autoc" CodeBuilder::CModule.generate!("containers") do |m| m << DataStructBuilder::HashSet.new("IntSet", {:type=>"int"}) end
IntSet
:
... typedef struct IntSet IntSet; struct IntSet {...} ... void IntSetCtor(IntSet*); void IntSetDtor(IntSet*); void IntSetPut(IntSet*, int); ...
IntSet
:
#include <stdio.h> #include "containers_auto.h" int main(int argc, char** argv) { IntSet set; IntSetCtor(&set); IntSetPut(&set, 0); IntSetPut(&set, 1); IntSetPut(&set, 0); printf("size(set)=%d\n", IntSetSize(&set)); printf("contains(1)==%d\n", IntSetContains(&set, 1)); IntSetDtor(&set); return 0; }
; , , ( API ). , , .
, .
PS
.
std::list std::list ).
, , . , , , copy-on-write .. , - , , , ..
AutoC , std::unordered_set ++.
(set), :
require "autoc" CodeBuilder::CModule.generate!("containers") do |m| m << DataStructBuilder::HashSet.new("IntSet", {:type=>"int"}) end
IntSet
:
... typedef struct IntSet IntSet; struct IntSet {...} ... void IntSetCtor(IntSet*); void IntSetDtor(IntSet*); void IntSetPut(IntSet*, int); ...
IntSet
:
#include <stdio.h> #include "containers_auto.h" int main(int argc, char** argv) { IntSet set; IntSetCtor(&set); IntSetPut(&set, 0); IntSetPut(&set, 1); IntSetPut(&set, 0); printf("size(set)=%d\n", IntSetSize(&set)); printf("contains(1)==%d\n", IntSetContains(&set, 1)); IntSetDtor(&set); return 0; }
; , , ( API ). , , .
, .
PS
.
std::list std::list ).
, , . , , , copy-on-write .. , - , , , ..
AutoC , std::unordered_set ++.
(set), :
require "autoc" CodeBuilder::CModule.generate!("containers") do |m| m << DataStructBuilder::HashSet.new("IntSet", {:type=>"int"}) end
IntSet
:
... typedef struct IntSet IntSet; struct IntSet {...} ... void IntSetCtor(IntSet*); void IntSetDtor(IntSet*); void IntSetPut(IntSet*, int); ...
IntSet
:
#include <stdio.h> #include "containers_auto.h" int main(int argc, char** argv) { IntSet set; IntSetCtor(&set); IntSetPut(&set, 0); IntSetPut(&set, 1); IntSetPut(&set, 0); printf("size(set)=%d\n", IntSetSize(&set)); printf("contains(1)==%d\n", IntSetContains(&set, 1)); IntSetDtor(&set); return 0; }
; , , ( API ). , , .
, .
PS
.
Source: https://habr.com/ru/post/171339/
All Articles