-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpokedatastructure.h
65 lines (49 loc) · 1.72 KB
/
pokedatastructure.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef POKEDATASTRUCTURE_H
#define POKEDATASTRUCTURE_H
#include <iostream>
#include <map>
#include <vector>
#include <cassert>
#include <stdint.h>
#include <algorithm>
#include "util.h"
class PokeDataStructure {
public:
PokeDataStructure();
~PokeDataStructure();
void add_pokemon(uint16_t poke_id, uint16_t name_id, uint8_t field_id, uint8_t field_level);
std::pair<uint8_t, uint8_t> get_field_move(uint16_t poke_id);
std::vector<uint16_t> get_pokemon_with_geq_field_move (uint16_t poke_id);
void print_level_order();
void self_test();
private:
std::map<uint16_t, uint16_t> pokemon_field_moves;
// ugh, hate having two maps
std::map<uint16_t, uint16_t> pokemon_names_to_reals;
std::map<uint16_t, uint16_t> pokemon_reals_to_names;
struct TreeNode {
// first is (field_id << 8) | field_level, second is poke_id
// for leaves, field signature
// for non-leaves, max value of left subtree
uint16_t data;
std::vector<uint16_t> poke_ids;
int height;
TreeNode *left;
TreeNode *right;
};
TreeNode *root;
TreeNode* find_vsplit (TreeNode *node,
uint16_t min, uint16_t max);
void collect_subtree (TreeNode *node, std::vector<uint16_t> *vec);
std::vector<uint16_t> range_query (uint16_t min, uint16_t max);
TreeNode* add_node (TreeNode *nod, uint16_t field_signature,
uint16_t poke_id);
bool is_leaf(TreeNode *node);
int height(TreeNode* node);
int get_balance(TreeNode *node);
TreeNode* left_rotate(TreeNode *x);
TreeNode* right_rotate(TreeNode *y);
void print_current_level (TreeNode* node, int level);
void post_order_delete(TreeNode *node);
};
#endif