Skip to content

Commit f8e12d5

Browse files
committed
Add comparison operators for CassUuid
1 parent 2b3fb19 commit f8e12d5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

include/cassandra.h

+26
Original file line numberDiff line numberDiff line change
@@ -11448,4 +11448,30 @@ cass_alloc_set_functions(CassMallocFunction malloc_func,
1144811448
} /* extern "C" */
1144911449
#endif
1145011450

11451+
#ifdef __cplusplus
11452+
/**
11453+
* Compare two UUIDs for ordering
11454+
*
11455+
* This operator is useful to use CassUuid variables as std::map keys, for
11456+
* instance.
11457+
*
11458+
* @param uuid1 A UUID
11459+
* @param uuid2 Another UUID
11460+
* @return true if, and only if, uuid1 is numerically less or equal than uuid2
11461+
*/
11462+
bool operator<(const CassUuid& uuid1, const CassUuid& uuid2);
11463+
11464+
/**
11465+
* Compare two UUIDs for equality
11466+
*
11467+
* This operator is useful to use CassUuid variables as std::map keys, for
11468+
* instance.
11469+
*
11470+
* @param uuid1 A UUID
11471+
* @param uuid2 Another UUID
11472+
* @return true if, and only if, uuid1 is numerically less or equal than uuid2
11473+
*/
11474+
bool operator==(const CassUuid& uuid1, const CassUuid& uuid2);
11475+
#endif
11476+
1145111477
#endif /* __CASS_H_INCLUDED__ */

src/uuids.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ static uint64_t set_version(uint64_t timestamp, uint8_t version) {
4444
return (timestamp & 0x0FFFFFFFFFFFFFFFLL) | (static_cast<uint64_t>(version) << 60);
4545
}
4646

47+
bool operator<(const CassUuid& uuid1, const CassUuid& uuid2) {
48+
if (uuid1.time_and_version == uuid2.time_and_version)
49+
return uuid1.clock_seq_and_node < uuid2.clock_seq_and_node;
50+
else
51+
return uuid1.time_and_version < uuid2.time_and_version;
52+
}
53+
54+
bool operator==(const CassUuid& uuid1, const CassUuid& uuid2) {
55+
return uuid1.time_and_version == uuid2.time_and_version
56+
&& uuid1.clock_seq_and_node == uuid2.clock_seq_and_node;
57+
}
58+
4759
extern "C" {
4860

4961
CassUuidGen* cass_uuid_gen_new() { return CassUuidGen::to(new UuidGen()); }

0 commit comments

Comments
 (0)