Skip to content

Commit

Permalink
Fixes the style of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed May 24, 2015
1 parent 3df8c9e commit a513b9e
Show file tree
Hide file tree
Showing 6 changed files with 582 additions and 700 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135 changes: 61 additions & 74 deletions examples/example1.cpp
Original file line number Diff line number Diff line change
@@ -1,110 +1,97 @@
#include <string>
#include <iostream>
#include <cstdlib>

#include "../radix_tree.hpp"

using namespace std;

radix_tree<string, int> tree;

void
insert()
{
tree["apache"] = 0;
tree["afford"] = 1;
tree["available"] = 2;
tree["affair"] = 3;
tree["avenger"] = 4;
tree["binary"] = 5;
tree["bind"] = 6;
tree["brother"] = 7;
tree["brace"] = 8;
tree["blind"] = 9;
tree["bro"] = 10;
radix_tree<std::string, int> tree;

void insert() {
tree["apache"] = 0;
tree["afford"] = 1;
tree["available"] = 2;
tree["affair"] = 3;
tree["avenger"] = 4;
tree["binary"] = 5;
tree["bind"] = 6;
tree["brother"] = 7;
tree["brace"] = 8;
tree["blind"] = 9;
tree["bro"] = 10;
}

void
longest_match(string key)
void longest_match(std::string key)
{
radix_tree<string, int>::iterator it;
radix_tree<std::string, int>::iterator it;

it = tree.longest_match(key);
it = tree.longest_match(key);

cout << "longest_match(\"" << key << "\"):" << endl;
std::cout << "longest_match(\"" << key << "\"):" << std::endl;

if (it != tree.end()) {
cout << " " << it->first << ", " << it->second << endl;
} else {
cout << " failed" << endl;
}
if (it != tree.end()) {
std::cout << " " << it->first << ", " << it->second << std::endl;
} else {
std::cout << " failed" << std::endl;
}
}

void
prefix_match(string key)
void prefix_match(std::string key)
{
vector<radix_tree<string, int>::iterator> vec;
vector<radix_tree<string, int>::iterator>::iterator it;
std::vector<radix_tree<std::string, int>::iterator> vec;
std::vector<radix_tree<std::string, int>::iterator>::iterator it;

tree.prefix_match(key, vec);
tree.prefix_match(key, vec);

cout << "prefix_match(\"" << key << "\"):" << endl;
std::cout << "prefix_match(\"" << key << "\"):" << std::endl;

for (it = vec.begin(); it != vec.end(); ++it) {
cout << " " << (*it)->first
<< ", " << (*it)->second
<< endl;
}
for (it = vec.begin(); it != vec.end(); ++it) {
std::cout << " " << (*it)->first << ", " << (*it)->second << std::endl;
}
}

void
greedy_match(string key)
void greedy_match(std::string key)
{
vector<radix_tree<string, int>::iterator> vec;
vector<radix_tree<string, int>::iterator>::iterator it;
std::vector<radix_tree<std::string, int>::iterator> vec;
std::vector<radix_tree<std::string, int>::iterator>::iterator it;

tree.greedy_match(key, vec);
tree.greedy_match(key, vec);

cout << "greedy_match(\"" << key << "\"):" << endl;
std::cout << "greedy_match(\"" << key << "\"):" << std::endl;

for (it = vec.begin(); it != vec.end(); ++it) {
cout << " " << (*it)->first
<< ", " << (*it)->second
<< endl;
}
for (it = vec.begin(); it != vec.end(); ++it) {
std::cout << " " << (*it)->first << ", " << (*it)->second << std::endl;
}
}

void
traverse()
{
radix_tree<string, int>::iterator it;
void traverse() {
radix_tree<std::string, int>::iterator it;

cout << "traverse:" << endl;
for (it = tree.begin(); it != tree.end(); ++it) {
cout << " " << it->first << ", " << it->second << endl;
}
std::cout << "traverse:" << std::endl;
for (it = tree.begin(); it != tree.end(); ++it) {
std::cout << " " << it->first << ", " << it->second << std::endl;
}
}

int
main(int argc, char **argv)
int main()
{
insert();
insert();

longest_match("binder");
longest_match("bracelet");
longest_match("apple");
longest_match("binder");
longest_match("bracelet");
longest_match("apple");

prefix_match("aff");
prefix_match("bi");
prefix_match("a");
prefix_match("aff");
prefix_match("bi");
prefix_match("a");

greedy_match("avoid");
greedy_match("bring");
greedy_match("attack");
greedy_match("avoid");
greedy_match("bring");
greedy_match("attack");

traverse();
traverse();

tree.erase("bro");
prefix_match("bro");
tree.erase("bro");
prefix_match("bro");

return 0;
return EXIT_SUCCESS;
}
Loading

0 comments on commit a513b9e

Please sign in to comment.