-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a221a4
commit 61bb36f
Showing
54 changed files
with
692 additions
and
890 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "OrderedSTTest.h" | ||
#include "STTest.h" | ||
#include <iomanip> | ||
|
||
namespace STTest { | ||
void init(OrderedST<std::string, int> &st, std::istream &is, std::ostream &os) { | ||
init(static_cast<ST<std::string, int> &>(st), is, os); | ||
os << "min = " << st.min().value_or(INVALID_KEY) << std::endl; | ||
os << "max = " << st.max().value_or(INVALID_KEY) << std::endl; | ||
} | ||
|
||
void removeSome(OrderedST<std::string, int> &st, std::ostream &os) { | ||
// remove the smallest keys | ||
for (int i = 0; i < st.size() / 2; ++i) { | ||
st.removeMin(); | ||
} | ||
os << "After removing the smallest " << st.size() / 2 << " keys, size = " << st.size() << ":" << std::endl; | ||
os << "--------------------------------" << std::endl; | ||
listAll(st, os); | ||
} | ||
|
||
void removeAll(OrderedST<std::string, int> &st, std::ostream &os) { | ||
// remove all the remaining keys | ||
while (!st.isEmpty()) { | ||
st.remove(st.select(st.size() / 2).value_or(INVALID_KEY)); | ||
} | ||
std::cout << "After removing the remaining keys, size = " << st.size() << ":" << std::endl; | ||
os << "--------------------------------" << std::endl; | ||
listAll(st, os); | ||
} | ||
|
||
void testOrderedST(OrderedST<std::string, int> &st, std::ostream &os) { | ||
// print keys in order using select | ||
os << "Testing select:" << std::endl; | ||
os << "--------------------------------" << std::endl; | ||
for (int i = 0; i < st.size(); ++i) { | ||
os << i << " " << st.select(i).value_or(INVALID_KEY) << std::endl; | ||
} | ||
os << std::endl; | ||
|
||
// test rank, floor, ceiling | ||
os << "key rank floor ceil" << std::endl; | ||
os << "-------------------" << std::endl; | ||
for (char i = 'A'; i <= 'Z'; ++i) { | ||
std::string s(1, i); | ||
os << std::setw(2) << s << " " | ||
<< std::setw(4) << st.rank(s) << " " | ||
<< std::setw(4) << st.floor(s).value_or(INVALID_KEY) << " " | ||
<< std::setw(4) << st.ceiling(s).value_or(INVALID_KEY) << std::endl; | ||
} | ||
os << std::endl; | ||
|
||
// test range search and range count | ||
std::vector<std::string> from = {"A", "Z", "X", "0", "B", "C"}; | ||
std::vector<std::string> to = {"Z", "A", "X", "Z", "G", "L"}; | ||
os << "range search" << std::endl; | ||
os << "-------------------" << std::endl; | ||
for (int i = 0; i < from.size(); ++i) { | ||
os << from[i] << "-" << to[i] << " (" << std::setw(2) << st.size(from[i], to[i]) << ") : "; | ||
for (const auto &s: st.keys(from[i], to[i])) { | ||
os << s << " "; | ||
} | ||
os << std::endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef ORDEREDSTTEST_H | ||
#define ORDEREDSTTEST_H | ||
|
||
|
||
#include <iostream> | ||
#include "OrderedST.h" | ||
|
||
namespace STTest { | ||
void init(OrderedST<std::string, int> &st, std::istream &is, std::ostream &os); | ||
|
||
void removeSome(OrderedST<std::string, int> &st, std::ostream &os); | ||
|
||
void removeAll(OrderedST<std::string, int> &st, std::ostream &os); | ||
|
||
void testOrderedST(OrderedST<std::string, int> &st, std::ostream &os); | ||
} | ||
|
||
|
||
#endif //ORDEREDSTTEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.