diff options
Diffstat (limited to 'Source/Library/Common')
-rw-r--r-- | Source/Library/Common/BasicString.class.cpp | 9 | ||||
-rw-r--r-- | Source/Library/Common/BasicString.class.h | 3 | ||||
-rw-r--r-- | Source/Library/Common/Map.class.h | 15 |
3 files changed, 18 insertions, 9 deletions
diff --git a/Source/Library/Common/BasicString.class.cpp b/Source/Library/Common/BasicString.class.cpp index ddb4e2c..125d420 100644 --- a/Source/Library/Common/BasicString.class.cpp +++ b/Source/Library/Common/BasicString.class.cpp @@ -183,3 +183,12 @@ BasicString<T> BasicString<T>::substr(s32int start, s32int size) { memcpy((u8int*)ret.m_string, (u8int*)(&m_string[start]), size * sizeof(T)); return ret; } + +template <typename T> +bool BasicString<T>::operator<(const BasicString<T>& other) const { + for (u32int i = 0; i < m_length && i < other.m_length; i++) { + if (m_string[i] < other.m_string[i]) return true; + } + if (m_length < other.m_length) return true; + return false; +} diff --git a/Source/Library/Common/BasicString.class.h b/Source/Library/Common/BasicString.class.h index 03d82c1..553c331 100644 --- a/Source/Library/Common/BasicString.class.h +++ b/Source/Library/Common/BasicString.class.h @@ -28,6 +28,9 @@ class BasicString { bool operator== (const BasicString<T> &other) const { return compare(other); } bool operator!= (const BasicString<T> &other) const { return !compare(other); } + bool operator<(const BasicString<T>& other) const; + bool operator>(const BasicString<T>& other) const { return (other < *this); } + BasicString<T>& append(const BasicString<T> &other); BasicString<T>& append(const T* string, u32int length); BasicString<T>& append(const T other); diff --git a/Source/Library/Common/Map.class.h b/Source/Library/Common/Map.class.h index 1270752..3428012 100644 --- a/Source/Library/Common/Map.class.h +++ b/Source/Library/Common/Map.class.h @@ -20,22 +20,19 @@ class Map { item_t* find(const K& key, item_t* start) { if (start == 0) return 0; if (start->key == key) return start; - if (start->key > key) return find(key, start->prev); - if (start->key < key) return find(key, start->next); + if (key < start->key) return find(key, start->prev); + else return find(key, start->next); return 0; } item_t* insert(const K& key, const V& value, item_t* start) { if (start == 0) return new item_t(key, value); - if (start->key == key) return 0; - if (start->key > key) { + if (start->key == key) return start; + if (key < start->key) { start->prev = insert(key, value, start->prev); - return start; - } - if (start->key < key) { + } else { start->next = insert(key, value, start->next); - return start; } - return 0; + return start; } public: |