blob: d6bd0c380a784eb8eacf8995f7499af5468c2325 [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001/*
2 * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef BTREE_HPP
18#define BTREE_HPP
19
20#include <iostream>
21#include <vector>
22#include <utils/threads.h>
23#include "MtpDebug.h"
24
25// A generic tree node class
26class Node {
27 int mtpid;
28 int mtpparentid;
29 std::string path;
30 int parentID;
31 Node* left;
32 Node* right;
33 Node* parent;
34
35public:
36 Node();
37 void setMtpid(int aMtpid);
38 void setPath(std::string aPath);
39 void setLeft(Node* aLeft);
40 void setRight(Node* aRight);
41 void setParent(Node* aParent);
42 void setMtpParentId(int id);
43 int Mtpid();
44 int getMtpParentId();
45 std::string getPath();
46 Node* Left();
47 Node* Right();
48 Node* Parent();
49 void addProperty(uint64_t property, uint64_t valueInt, std::string valueStr, int dataType);
50 void updateProperty(uint64_t property, uint64_t valueInt, std::string valueStr, int dataType);
51 void addProperties(int storageID, int parent_object);
52 uint64_t getIntProperty(uint64_t property);
53 struct mtpProperty {
54 uint64_t property;
55 uint64_t valueInt;
56 std::string valueStr;
57 int dataType;
58 };
59 std::vector<mtpProperty>& getMtpProps();
60 std::vector<mtpProperty> mtpProp;
61};
62
63// Binary Search Tree class
64class Tree {
65 Node* root;
66public:
67 Tree();
68 ~Tree();
69 Node* Root() {
70 MTPD("root: %d\n", root);
71 return root;
72 };
73 Node* addNode(int mtpid, std::string path);
74 void setMtpParentId(int mtpparentid, Node* node);
75 Node* findNode(int key, Node* parent);
76 void getmtpids(Node* node, std::vector<int>* mtpids);
77 void deleteNode(int key);
78 Node* min(Node* node);
79 Node* max(Node* node);
80 Node* successor(int key, Node* parent);
81 Node* predecessor(int key, Node* parent);
82 std::string getPath(Node* node);
83 int getMtpParentId(Node* node);
84 Node* findNodePath(std::string path, Node* node);
85 Node* getNext(Node* node);
86 int getCount();
87
88private:
89 Node* addNode(int mtpid, Node* leaf, std::string path);
90 void freeNode(Node* leaf);
91 int count;
92};
93
94#endif