Giter Club home page Giter Club logo

c-dict's Introduction

C-dict

Build Status

####API

int dict_init(dict_t *); 

int dict_size(dict_t *); 

void dict_set(dict_t *, char *, void *); 

int dict_get(dict_t *, char *, void **); 

int dict_del(dict_t *, char *); 

void dict_keys(dict_t *, char **); 

void dict_reset(dict_t *); 

void dict_destory(dict_t *); 

int dict_iter(dict_t *, char **, void **); 

####Test

cd test
make test

####Data Type

dict_t;

####Example

	dict_t *d = (dict_t *)malloc(sizeof(dict_t));
	char *var; 
	
	dict_init(d); 
	
	dict_set(d, "key1", "var1"); 
	dict_set(d, "key2", "var2"); 
	dict_set(d, "key3", "var3"); 
	
	dict_get(d, "key1", (void **)&var); 
	printf("key1=>%s\n", var);
	
	printf("dict size:%d\n", dict_size(d));
	
	if (1 == dict_del(d, "key3"))
		printf("del key3 done\n");
	
	char **ks = (char **)malloc(dict_size(d)*sizeof(char*)); 
	int i; 
	dict_keys(d, ks); 
	for(i = 0; i < dict_size(d); i++)
		printf("%s ",*(ks+i) );
	printf("\n");
	
	char *k, *v; 
	while(dict_iter(d, &k, (void **)&v))
		printf("%s = >%s\n", k, v);
	
	dict_reset(d); 
	
	dict_destory(d); 
	free(d); 

TODO

dict_merge()

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.