style fixes in c example

main
Haneef Mubarak 10 years ago
parent 91c58752fa
commit 28424d734b
  1. 44
      examples/simple_example.c

@ -9,40 +9,42 @@
const char DBPath[] = "/tmp/rocksdb_simple_example"; const char DBPath[] = "/tmp/rocksdb_simple_example";
int main (int argc, char **argv) { int main(int argc, char **argv) {
rocksdb_t *db; rocksdb_t *db;
rocksdb_options_t *options = rocksdb_options_create (); rocksdb_options_t *options = rocksdb_options_create();
// Optimize RocksDB. This is the easiest way to get RocksDB to perform well // Optimize RocksDB. This is the easiest way to
int cpus = sysconf (_SC_NPROCESSORS_ONLN); // get number of online cores // get RocksDB to perform well
rocksdb_options_increase_parallelism (options, cpus); int cpus = sysconf(_SC_NPROCESSORS_ONLN); // get # of online cores
rocksdb_options_optimize_level_style_compaction (options, 0); rocksdb_options_increase_parallelism(options, cpus);
rocksdb_options_optimize_level_style_compaction(options, 0);
// create the DB if it's not already present // create the DB if it's not already present
rocksdb_options_set_create_if_missing (options, 1); rocksdb_options_set_create_if_missing(options, 1);
// open DB // open DB
char *err = NULL; char *err = NULL;
db = rocksdb_open (options, DBPath, &err); db = rocksdb_open(options, DBPath, &err);
assert (!err); assert(!err);
// Put key-value // Put key-value
rocksdb_writeoptions_t *writeoptions = rocksdb_writeoptions_create (); rocksdb_writeoptions_t *writeoptions = rocksdb_writeoptions_create();
const char key[] = "key"; const char key[] = "key";
char *value = "value"; char *value = "value";
rocksdb_put (db, writeoptions, key, strlen (key), value, strlen (value), &err); rocksdb_put(db, writeoptions, key, strlen (key), value, \
assert (!err); strlen (value), &err);
assert(!err);
// Get value // Get value
rocksdb_readoptions_t *readoptions = rocksdb_readoptions_create (); rocksdb_readoptions_t *readoptions = rocksdb_readoptions_create();
size_t len; size_t len;
value = rocksdb_get (db, readoptions, key, strlen (key), &len, &err); value = rocksdb_get(db, readoptions, key, strlen (key), &len, &err);
assert (!err); assert(!err);
assert (strcmp (value, "value") == 0); assert(strcmp(value, "value") == 0);
free (value); free(value);
// cleanup // cleanup
rocksdb_writeoptions_destroy (writeoptions); rocksdb_writeoptions_destroy(writeoptions);
rocksdb_readoptions_destroy (readoptions); rocksdb_readoptions_destroy(readoptions);
rocksdb_options_destroy (options); rocksdb_options_destroy(options);
rocksdb_close (db); rocksdb_close(db);
return 0; return 0;
} }

Loading…
Cancel
Save