From 37e364b2c6cc7487a1c888d256a73e5337bb7189 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 14 Jun 2023 00:50:34 +0100 Subject: initial commit --- src/T2DLL/LComparator.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/T2DLL/LComparator.cpp (limited to 'src/T2DLL/LComparator.cpp') 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; +} -- cgit v1.2.3