feat(README): update the readme
This commit is contained in:
17
README.md
17
README.md
@@ -7,7 +7,8 @@ Example of working with a singly linked list (sll):
|
|||||||
```c
|
```c
|
||||||
char *a = "one";
|
char *a = "one";
|
||||||
char *b = "two";
|
char *b = "two";
|
||||||
ds_sll_t *ll = ds_sll_new_node(a); // [ "one" ]
|
ds_sll_t *ll = ds_sll_init();
|
||||||
|
ds_sll_insert(ll, a); // [ "one" ]
|
||||||
ds_sll_insert(ll, b); // [ "one", "two" ]
|
ds_sll_insert(ll, b); // [ "one", "two" ]
|
||||||
ds_ll_foreach(ds_sll_t, ll) {
|
ds_ll_foreach(ds_sll_t, ll) {
|
||||||
puts(cur->data);
|
puts(cur->data);
|
||||||
@@ -22,28 +23,28 @@ datatypes.
|
|||||||
|
|
||||||
## Hash Map
|
## Hash Map
|
||||||
```c
|
```c
|
||||||
struct complex {
|
typedef struct {
|
||||||
int num;
|
int num;
|
||||||
char *str;
|
char *str;
|
||||||
};
|
} complex ;
|
||||||
|
|
||||||
struct complex *a = calloc(1, sizeof(struct complex));
|
complex *a = calloc(1, sizeof(complex));
|
||||||
a->num = 1;
|
a->num = 1;
|
||||||
a->str = "abc";
|
a->str = "abc";
|
||||||
struct complex *b = calloc(1, sizeof(struct complex));
|
complex *b = calloc(1, sizeof(complex));
|
||||||
b->num = 2;
|
b->num = 2;
|
||||||
b->str = "def";
|
b->str = "def";
|
||||||
|
|
||||||
ds_hmp_t *hmp = ds_hmp_init(101);
|
ds_hmp_t *hmp = ds_hmp_init(101);
|
||||||
ds_hmp_insert(hmp, a->str, a); // [ (23)[ [ a->str, a ] ] ]
|
ds_hmp_insert(hmp, a->str, a); // [ (23)[ [ a->str, a ] ] ]
|
||||||
ds_hmp_insert(hmp, b->str, b); // [ (23)[ [ a->str, a ] ], (58)[ [ b->str, b ] ]
|
ds_hmp_insert(hmp, b->str, b); // [ (23)[ [ a->str, a ] ], (58)[ [ b->str, b ] ]
|
||||||
struct complex *pa = ds_hmp_remove(hmp, a->str); // a
|
complex *pa = ds_hmp_remove(hmp, a->str); // a
|
||||||
free(pa->str);
|
free(pa->str);
|
||||||
free(pa);
|
free(pa);
|
||||||
ds_hmp_free(&hmp);
|
ds_hmp_free(&hmp, NULL);
|
||||||
free(b);
|
free(b);
|
||||||
```
|
```
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] more data structures
|
- [ ] more data structures
|
||||||
- [ ] tests
|
- [x] tests
|
||||||
|
Reference in New Issue
Block a user