Mercurial > nomad > old-fuse
changeset 29:ab373aa76e6e
common: add a function to compare object IDs
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 29 Jun 2015 10:27:03 -0400 |
parents | 5194073f7a35 |
children | 34f3f1c155e4 |
files | src/common/CMakeLists.txt src/common/include/nomad/types.h src/common/oid.c |
diffstat | 3 files changed, 44 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/common/CMakeLists.txt Mon Jun 29 10:20:21 2015 -0400 +++ b/src/common/CMakeLists.txt Mon Jun 29 10:27:03 2015 -0400 @@ -21,6 +21,7 @@ # add_library(nomad_common SHARED + oid.c uuid.c vclock.c )
--- a/src/common/include/nomad/types.h Mon Jun 29 10:20:21 2015 -0400 +++ b/src/common/include/nomad/types.h Mon Jun 29 10:27:03 2015 -0400 @@ -29,9 +29,9 @@ /* object id */ struct noid { - uint32_t ds; - uint32_t _reserved; /* must be zero */ - uint64_t uniq; + uint32_t ds; /* dataset id */ + uint32_t _reserved; /* must be zero */ + uint64_t uniq; /* dataset-local id */ }; /* version vector */ @@ -51,6 +51,8 @@ uint8_t raw[16]; }; +extern int noid_cmp(const struct noid *n1, const struct noid *n2); + extern struct nvclock *nvclock_alloc(uint16_t nodes); extern void nvclock_free(struct nvclock *clock);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/oid.c Mon Jun 29 10:27:03 2015 -0400 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include <nomad/types.h> + +int noid_cmp(const struct noid *n1, const struct noid *n2) +{ + if (n1->ds < n2->ds) + return -1; + if (n1->ds > n2->ds) + return 1; + + if (n1->uniq < n2->uniq) + return -1; + if (n1->uniq > n2->uniq) + return 1; + + return 0; +}