mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
TinySet bugfix, add "append"
This commit is contained in:
parent
a854fbbe76
commit
bd71d8044b
2 changed files with 58 additions and 1 deletions
|
@ -43,6 +43,20 @@ struct TinySet {
|
|||
slowLookup_->push_back(t);
|
||||
return slowLookup_->back();
|
||||
}
|
||||
void append(const TinySet<T, MaxFastSize> &other) {
|
||||
size_t otherSize = other.size();
|
||||
if (size() + otherSize <= MaxFastSize) {
|
||||
// Fast case
|
||||
for (int i = 0; i < otherSize; i++) {
|
||||
fastLookup_[fastCount + i] = other.fastLookup_[i];
|
||||
}
|
||||
fastCount += other.fastCount;
|
||||
} else {
|
||||
for (int i = 0; i < otherSize; i++) {
|
||||
push_back(other[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool contains(T t) const {
|
||||
for (int i = 0; i < fastCount; i++) {
|
||||
if (fastLookup_[i] == t)
|
||||
|
@ -79,7 +93,7 @@ struct TinySet {
|
|||
return fastCount == 0;
|
||||
}
|
||||
size_t size() const {
|
||||
if (fastCount <= MaxFastSize) {
|
||||
if (!slowLookup_) {
|
||||
return fastCount;
|
||||
} else {
|
||||
return slowLookup_->size() + MaxFastSize;
|
||||
|
@ -92,6 +106,9 @@ struct TinySet {
|
|||
return (*slowLookup_)[index - MaxFastSize];
|
||||
}
|
||||
}
|
||||
const T &back() const {
|
||||
return (*this)[size() - 1];
|
||||
}
|
||||
|
||||
private:
|
||||
void insertSlow(T t) {
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <jni.h>
|
||||
#endif
|
||||
|
||||
#include "Common/Data/Collections/TinySet.h"
|
||||
#include "Common/Data/Text/Parsers.h"
|
||||
#include "Common/Data/Text/WrapText.h"
|
||||
#include "Common/Data/Encoding/Utf8.h"
|
||||
|
@ -308,6 +309,44 @@ bool TestParsers() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TestTinySet() {
|
||||
TinySet<int, 4> a;
|
||||
EXPECT_EQ_INT((int)a.size(), 0);
|
||||
a.push_back(1);
|
||||
EXPECT_EQ_INT((int)a.size(), 1);
|
||||
a.push_back(2);
|
||||
EXPECT_EQ_INT((int)a.size(), 2);
|
||||
TinySet<int, 4> b;
|
||||
b.push_back(8);
|
||||
b.push_back(9);
|
||||
b.push_back(10);
|
||||
EXPECT_EQ_INT((int)b.size(), 3);
|
||||
|
||||
a.append(b);
|
||||
EXPECT_EQ_INT((int)a.size(), 5);
|
||||
EXPECT_EQ_INT((int)b.size(), 3);
|
||||
|
||||
b.append(b);
|
||||
EXPECT_EQ_INT((int)b.size(), 6);
|
||||
|
||||
EXPECT_EQ_INT(a[0], 1);
|
||||
EXPECT_EQ_INT(a[1], 2);
|
||||
EXPECT_EQ_INT(a[2], 8);
|
||||
EXPECT_EQ_INT(a[3], 9);
|
||||
EXPECT_EQ_INT(a[4], 10);
|
||||
a.append(a);
|
||||
EXPECT_EQ_INT(a.size(), 10);
|
||||
EXPECT_EQ_INT(a[9], 10);
|
||||
|
||||
b.push_back(11);
|
||||
EXPECT_EQ_INT((int)b.size(), 7);
|
||||
b.push_back(12);
|
||||
EXPECT_EQ_INT((int)b.size(), 8);
|
||||
b.push_back(13);
|
||||
EXPECT_EQ_INT(b.size(), 9);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestVFPUSinCos() {
|
||||
float sine, cosine;
|
||||
InitVFPUSinCos();
|
||||
|
@ -792,6 +831,7 @@ TestItem availableTests[] = {
|
|||
TEST_ITEM(AndroidContentURI),
|
||||
TEST_ITEM(ThreadManager),
|
||||
TEST_ITEM(WrapText),
|
||||
TEST_ITEM(TinySet),
|
||||
};
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
|
Loading…
Add table
Reference in a new issue