GithubHelp home page GithubHelp logo

libcborg's Introduction

libcborg

This library is developed for the CborgDB project.

Build and Install

$ git clone https://github.com/cborgdb/libcborg.git
$ cd libcborg
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make test
$ sudo make install

Uninstall

$ sudo make uninstall

Usage and build

  • Bitset
$ gcc bitset_example.c -o bitset_example -lcborg
$ ./bitset_example
bs: 1111011111
bs_string: 1111011111
#include <stdio.h>
#include <cborg/ds/bitset.h>

int main() {
  // bitset : 0000000000
  bitset_t *bs = cb_ds_bitset_new(10);

  // return 0
  cb_ds_bitset_count(bs);

  // return 10
  cb_ds_bitset_size(bs);

  // bitset: 1000000000
  cb_ds_bitset_set(bs, 0, true);
  
  // return true
  cb_ds_bitset_test(bs,0);

  // return false
  cb_ds_bitset_test(bs,1);

  // return true because bs have bit set 
  cb_ds_bitset_any(bs);

  // return false because bs have bit set
  cb_ds_bitset_none(bs);

  // return false 
  cb_ds_bitset_all(bs);
  
  // bitset: 0111111111
  cb_ds_bitset_flip(bs);

  // bitset: 0000000000
  cb_ds_bitset_reset(bs);
  
  // bitset: 1111111111
  cb_ds_bitset_flip(bs);

  // bitset: 1111011111
  cb_ds_bitset_set(bs, 4, false);

  // write bitset to file
  cb_ds_bitset_write(bs, "./bitset.bs");

  // read bitset from file
  bitset_t *bs_read = cb_ds_bitset_read("./bitset.bs");

  char *bs_string = cb_ds_bitset_to_string(bs);
  char *bs_read_string = cb_ds_bitset_to_string(bs_read);
  
  // printf
  // bs: 1111011111
  // bs_read: 1111011111
  printf("bs: %s\n",bs_string);
  printf("bs_read: %s\n",bs_read_string);

  // free
  free(bs_string);
  cb_ds_bitset_delete(bs);
  free(bs_read_string);
  cb_ds_bitset_delete(bs_read);
  return 0;
}
  • Bloom
$ gcc bloom_example.c -o bloom_example -lcborg
$ ./bloom_example
#include <stdio.h>
#include <cborg/ds/bloom.h>
#include <cborg/hash.h>

int main() {
  bloom_filter_t *b1 = cb_ds_bloom_new(cb_hash_fnv1a, cb_hash_murmur2_64a, 1000);
  cb_ds_bloom_insert(b1, "hello", 6);
  cb_ds_bloom_insert(b1, "hello world!", 12);
  cb_ds_bloom_delete(&b1);
  return 0;
}
  • Btree [TODO]
$ gcc btree_example.c -o btree_example -lcborg
$ ./btree_example
#include <stdio.h>
#include <cborg/ds/btree.h>

int main() {
  return 0;
}
  • Hash
$ gcc hash_example.c -o hash_example -lcborg
$ ./hash_example
11900548196712136313
9114364940175044080
8796868307739761162
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <cborg/hash.h>

int main() {
  char *data = "hashme";
  // fnv1a
  uint64_t hfnv = cb_hash_fnv1a(data, 7);
  printf("%"PRIu64"\n",hfnv);

  // city
  uint64_t hc64 = cb_hash_city64(data, 7);
  printf("%"PRIu64"\n",hc64);

  // murmur2_64a
  uint64_t hm64 = cb_hash_murmur2_64a(data, 7);
  printf("%"PRIu64"\n",hm64);

  return 0;
}
  • Endianness
$ gcc endianness_example.c -o endianness_example -lcborg
$ ./endianness_example
is_little_endian = 1
8961
1732584193
17279655951921914625
#include <stdio.h>
#include <inttypes.h>
#include <cborg/os/endianness.h>

int main() {
  printf("cb_is_little_endian = %d\n", cb_is_little_endian());
  printf("%u\n", cb_bswap16(0x0123));
  printf("%u\n", cb_bswap32(0x01234567u));
  printf("%"PRIu64"\n", cb_bswap64(0x0123456789ABCDEFllu));
  return 0;
}

License

???

libcborg's People

Contributors

abenhlal avatar

Stargazers

 avatar

Watchers

 avatar  avatar

libcborg's Issues

read/write vs recv/send

Hello @abenhlal,

I would suggest using the recv and send instead of read and write on the socket handler.
I try to list below the reason that might help to take understand :

  • read and write are very specific to linux if you think about portability to others operating system recv and send are more portable.
  • read and write do not leave the possibility configure multiple flags which are very usefuly if later you decide to make the lib asynchronous for ex( with select & poll ) or add a TLS layer for communicating.
  • read and write are generic (for all file descriptor), in the socket context it make more sens to use send/recv.

What do you think?

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.