diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-14 00:50:34 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-14 00:50:34 +0100 |
commit | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (patch) | |
tree | eaf6e857382eef16c2dd940eb4125536fbe068bd /src/T2DLL/LComparator.cpp | |
download | t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.tar.gz t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/LComparator.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/T2DLL/LComparator.cpp b/src/T2DLL/LComparator.cpp new file mode 100644 index 0000000..649075d --- /dev/null +++ b/src/T2DLL/LComparator.cpp @@ -0,0 +1,79 @@ +#include "LComparator.h" + +LComparator* LComparator::sComparator; + +LComparator::LComparator() { + sComparator = NULL; +} + +/*virtual*/ LComparator::~LComparator() { +} + +/*virtual*/ int LComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + const unsigned char *a = (const unsigned char *) inItemOne; + const unsigned char *b = (const unsigned char *) inItemTwo; + unsigned int size = inSizeOne; + if (inSizeTwo < inSizeOne) + size = inSizeTwo; + + while (size > 0) { + if (*a != *b) + return *a - *b; + a++; + b++; + size--; + } + + return inSizeOne - inSizeTwo; +} + +/*virtual*/ BOOL LComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + return Compare(inItemOne, inItemTwo, inSizeOne, inSizeTwo) == 0; +} + +/*virtual*/ int LComparator::CompareToKey(const void* inItem, unsigned int inSize, const void* inKey) const { +#line 86 + _ASSERT("CompareToKey not implemented"); + return 1; +} + +/*virtual*/ BOOL LComparator::IsEqualToKey(const void* inItem, unsigned int inSize, const void* inKey) const { + return CompareToKey(inItem, inSize, inKey) == 0; +} + +LComparator* LComparator::GetComparator() { + if (!sComparator) + sComparator = new LComparator; + return sComparator; +} + +/*virtual*/ LComparator* LComparator::Clone() { + return new LComparator; +} + +LLongComparator* LLongComparator::sLongComparator; + +LLongComparator::LLongComparator() { + sLongComparator = NULL; +} + +/*virtual*/ LLongComparator::~LLongComparator() { +} + +/*virtual*/ int LLongComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + return *((const long *) inItemOne) - *((const long *) inItemTwo); +} + +/*virtual*/ BOOL LLongComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + return *((const long *) inItemOne) == *((const long *) inItemTwo); +} + +LLongComparator* LLongComparator::GetComparator() { + if (!sLongComparator) + sLongComparator = new LLongComparator; + return sLongComparator; +} + +/*virtual*/ LComparator* LLongComparator::Clone() { + return new LLongComparator; +} |