Skip to content

Commit

Permalink
Allow for a custom user-provided cmp_fn in config.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkgutierrez committed May 9, 2018
1 parent 0bbdf41 commit 4b70559
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/sdsdkv-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ struct sdsdkv_client : public personality {
//
ch_placement_find_closest(
m_place,
// TODO(skg) How to properly handle arbitrary data?
// TODO(skg) How to properly handle arbitrary-sized data (e.g., data
// less than sizeof(uint64_t))?
*(uint64_t *)(key),
replication,
server_indices
Expand Down
3 changes: 3 additions & 0 deletions src/sdsdkv-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class sdsdkv_iconfig {
//
sdsdkv_config_db db_type;
//
sdsdkv_compare_fn cmp_fn;
//
std::string group_name;
//
std::string db_path;
Expand All @@ -88,6 +90,7 @@ class sdsdkv_iconfig {
personality = config.personality;
hash_be = config.hash_be;
db_type = config.db_type;
cmp_fn = config.cmp_fn;
group_name = string(config.group_name);
db_path = string(config.db_path);
db_name = string(config.db_name);
Expand Down
3 changes: 1 addition & 2 deletions src/sdsdkv-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ struct sdsdkv_server : public personality {
m_config->db_name.c_str(),
m_config->db_path.c_str(),
sdsdkv_iconfig::get_real_db_type(m_config->db_type),
// TODO(skg) Make a user param.
SDSKV_COMPARE_DEFAULT,
m_config->cmp_fn,
&m_dbid
);
if (rc != SDSKV_SUCCESS) return sdskv2irc(rc);
Expand Down
9 changes: 9 additions & 0 deletions src/sdsdkv.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ extern "C" {
/** Convenience definition (in case anyone needs this). */
#define SDSDKV 1

/** Default comparison function type. */
#define SDSDKV_COMPARE_DEFAULT NULL

/** Custom comparison function type. */
typedef int (*sdsdkv_compare_fn)(const void*, size_t, const void*, size_t);

/** External context type. */
typedef void* sdsdkv_context;

Expand Down Expand Up @@ -97,6 +103,7 @@ enum sdsdkv_config_db {
SDSDKV_DB_LEVELDB
};


// TODO(skg) Allow for two modes of operation:
// - Total lash-up
// - Connect
Expand All @@ -111,6 +118,8 @@ typedef struct sdsdkv_config {
sdsdkv_config_hashing hash_be;
/** Database type. */
sdsdkv_config_db db_type;
/** Key comparison function. */
sdsdkv_compare_fn cmp_fn;
/** Group name. */
char *group_name;
/** If applicable, the path where database files will be written. */
Expand Down
4 changes: 3 additions & 1 deletion tests/trivial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ main(int argc, char **argv)
/* .init_comm = */
MPI_COMM_WORLD,
/* .personality = */
(rank == 0) ? SDSDKV_PERSONALITY_SERVER: SDSDKV_PERSONALITY_CLIENT,
(rank == 0) ? SDSDKV_PERSONALITY_SERVER : SDSDKV_PERSONALITY_CLIENT,
/* .hash_be = */
SDSDKV_HASHING_CH_PLACEMENT,
/* .db_type = */
SDSDKV_DB_LEVELDB,
/* .cmp_fn= */
SDSDKV_COMPARE_DEFAULT,
/* .group_name = */
(char *)"groupname",
/* .db_path = */
Expand Down

0 comments on commit 4b70559

Please sign in to comment.