bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1 | /* |
| 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 |
| 26 | class Node { |
| 27 | int mtpid; |
| 28 | int mtpparentid; |
| 29 | std::string path; |
| 30 | int parentID; |
| 31 | Node* left; |
| 32 | Node* right; |
| 33 | Node* parent; |
| 34 | |
| 35 | public: |
| 36 | Node(); |
| 37 | void setMtpid(int aMtpid); |
| 38 | void setPath(std::string aPath); |
Dees Troy | 2e07c04 | 2014-09-04 15:00:57 +0000 | [diff] [blame^] | 39 | void rename(std::string aPath); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 40 | void setLeft(Node* aLeft); |
| 41 | void setRight(Node* aRight); |
| 42 | void setParent(Node* aParent); |
| 43 | void setMtpParentId(int id); |
| 44 | int Mtpid(); |
| 45 | int getMtpParentId(); |
| 46 | std::string getPath(); |
| 47 | Node* Left(); |
| 48 | Node* Right(); |
| 49 | Node* Parent(); |
| 50 | void addProperty(uint64_t property, uint64_t valueInt, std::string valueStr, int dataType); |
| 51 | void updateProperty(uint64_t property, uint64_t valueInt, std::string valueStr, int dataType); |
| 52 | void addProperties(int storageID, int parent_object); |
| 53 | uint64_t getIntProperty(uint64_t property); |
| 54 | struct mtpProperty { |
| 55 | uint64_t property; |
| 56 | uint64_t valueInt; |
| 57 | std::string valueStr; |
| 58 | int dataType; |
| 59 | }; |
| 60 | std::vector<mtpProperty>& getMtpProps(); |
| 61 | std::vector<mtpProperty> mtpProp; |
| 62 | }; |
| 63 | |
| 64 | // Binary Search Tree class |
| 65 | class Tree { |
| 66 | Node* root; |
| 67 | public: |
| 68 | Tree(); |
| 69 | ~Tree(); |
| 70 | Node* Root() { |
| 71 | MTPD("root: %d\n", root); |
| 72 | return root; |
| 73 | }; |
| 74 | Node* addNode(int mtpid, std::string path); |
| 75 | void setMtpParentId(int mtpparentid, Node* node); |
| 76 | Node* findNode(int key, Node* parent); |
| 77 | void getmtpids(Node* node, std::vector<int>* mtpids); |
| 78 | void deleteNode(int key); |
| 79 | Node* min(Node* node); |
| 80 | Node* max(Node* node); |
| 81 | Node* successor(int key, Node* parent); |
| 82 | Node* predecessor(int key, Node* parent); |
| 83 | std::string getPath(Node* node); |
| 84 | int getMtpParentId(Node* node); |
| 85 | Node* findNodePath(std::string path, Node* node); |
| 86 | Node* getNext(Node* node); |
| 87 | int getCount(); |
| 88 | |
| 89 | private: |
| 90 | Node* addNode(int mtpid, Node* leaf, std::string path); |
| 91 | void freeNode(Node* leaf); |
| 92 | int count; |
| 93 | }; |
| 94 | |
| 95 | #endif |