source3.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. #ifndef __source3_H__
  2. #define __source3_H__
  3. #include <iostream>
  4. #include <vector>
  5. #include <math.h>
  6. using namespace std;
  7. class Triehard // compressed decimal trie
  8. // constructor should make 1-10 base nodes that are empty for search to work
  9. // magnitude is 1 for length 1, so it must be >= 1
  10. // no more flag, instead we have a count field which counts the number of instances
  11. // the node represents. A small change, but much more functionality
  12. {
  13. private:
  14. class Trienode
  15. {
  16. private:
  17. int magnitude;
  18. int count;
  19. Trienode * one;
  20. Trienode * two;
  21. Trienode * three;
  22. Trienode * four;
  23. Trienode * five;
  24. Trienode * six;
  25. Trienode * seven;
  26. Trienode * eight;
  27. Trienode * nine;
  28. Trienode * ten;
  29. public:
  30. Trienode(int magnitude, int count):
  31. magnitude{magnitude}, count{count}
  32. {
  33. one = nullptr;
  34. two = nullptr;
  35. three = nullptr;
  36. four = nullptr;
  37. five = nullptr;
  38. six = nullptr;
  39. seven = nullptr;
  40. eight = nullptr;
  41. nine = nullptr;
  42. ten = nullptr;
  43. }
  44. ~Trienode()
  45. {
  46. delete one;
  47. delete two;
  48. delete three;
  49. delete four;
  50. delete five;
  51. delete six;
  52. delete seven;
  53. delete eight;
  54. delete nine;
  55. delete ten;
  56. }
  57. int getMag()
  58. {
  59. return magnitude;
  60. }
  61. int getCount()
  62. {
  63. return count;
  64. }
  65. Trienode * getOne()
  66. {
  67. return one;
  68. }
  69. Trienode * getTwo()
  70. {
  71. return two;
  72. }
  73. Trienode * getThree()
  74. {
  75. return three;
  76. }
  77. Trienode * getFour()
  78. {
  79. return four;
  80. }
  81. Trienode * getFive()
  82. {
  83. return five;
  84. }
  85. Trienode * getSix()
  86. {
  87. return six;
  88. }
  89. Trienode * getSeven()
  90. {
  91. return seven;
  92. }
  93. Trienode * getEight()
  94. {
  95. return eight;
  96. }
  97. Trienode * getNine()
  98. {
  99. return nine;
  100. }
  101. Trienode * getTen()
  102. {
  103. return ten;
  104. }
  105. void addMag()
  106. {
  107. ++magnitude;
  108. }
  109. void subMag()
  110. {
  111. --magnitude;
  112. }
  113. void addCount()
  114. {
  115. ++count;
  116. }
  117. void subCount()
  118. {
  119. --count;
  120. }
  121. void zeroCount()
  122. {
  123. count = 0;
  124. }
  125. void setCount(int x)
  126. {
  127. count = x;
  128. }
  129. Trienode * setOne(int mag, int cnt)
  130. {
  131. one = new Trienode(mag, cnt);
  132. return one;
  133. }
  134. Trienode * setTwo(int mag, int cnt)
  135. {
  136. two = new Trienode(mag, cnt);
  137. return two;
  138. }
  139. Trienode * setThree(int mag, int cnt)
  140. {
  141. three = new Trienode(mag, cnt);
  142. return three;
  143. }
  144. Trienode * setFour(int mag, int cnt)
  145. {
  146. four = new Trienode(mag, cnt);
  147. return four;
  148. }
  149. Trienode * setFive(int mag, int cnt)
  150. {
  151. five = new Trienode(mag, cnt);
  152. return five;
  153. }
  154. Trienode * setSix(int mag, int cnt)
  155. {
  156. six = new Trienode(mag, cnt);
  157. return six;
  158. }
  159. Trienode * setSeven(int mag, int cnt)
  160. {
  161. seven = new Trienode(mag, cnt);
  162. return seven;
  163. }
  164. Trienode * setEight(int mag, int cnt)
  165. {
  166. eight = new Trienode(mag, cnt);
  167. return eight;
  168. }
  169. Trienode * setNine(int mag, int cnt)
  170. {
  171. nine = new Trienode(mag, cnt);
  172. return nine;
  173. }
  174. Trienode * setTen(int mag, int cnt)
  175. {
  176. ten = new Trienode(mag, cnt);
  177. return ten;
  178. }
  179. void copyOne(Trienode * node)
  180. {
  181. one = node;
  182. }
  183. void copyTwo(Trienode * node)
  184. {
  185. two = node;
  186. }
  187. void copyThree(Trienode * node)
  188. {
  189. three = node;
  190. }
  191. void copyFour(Trienode * node)
  192. {
  193. four = node;
  194. }
  195. void copyFive(Trienode * node)
  196. {
  197. five = node;
  198. }
  199. void copySix(Trienode * node)
  200. {
  201. six = node;
  202. }
  203. void copySeven(Trienode * node)
  204. {
  205. seven = node;
  206. }
  207. void copyEight(Trienode * node)
  208. {
  209. eight = node;
  210. }
  211. void copyNine(Trienode * node)
  212. {
  213. nine = node;
  214. }
  215. void copyTen(Trienode * node)
  216. {
  217. ten = node;
  218. }
  219. int sumMag()
  220. {
  221. if (left && right) return magnitude + left->sumMag() + right->sumMag();
  222. if (left) return magnitude + left->sumMag();
  223. if (right) return magnitude + right->sumMag();
  224. return magnitude;
  225. }
  226. int sumCount()
  227. {
  228. if (left && right) return 1 + left->sumCount() + right->sumCount();
  229. if (left) return 1 + left->sumCount();
  230. if (right) return 1 + right->sumCount();
  231. return 1;
  232. }
  233. };
  234. vector<Trienode *> nodes(10);
  235. public:
  236. Triehard() // Initializes both sides as empty, but makes it searchable, mutatable
  237. {
  238. for (int i = 0; i < 10; ++i)
  239. {
  240. nodes[i] = nullptr;
  241. }
  242. }
  243. ~Triehard() // Same concern (syntax) as nodes, don't forget to write an erase method as well, maybe an empty/wipe
  244. {
  245. for (int i = 0; i < 10; ++i)
  246. {
  247. delete nodes[i];
  248. }
  249. }
  250. // build an array of what is "processed" so far. then when a flag is hit, print that array.
  251. void mainPrint(Trienode * curnode, vector<int> * chars, int val)
  252. {
  253. if (!curnode) return;
  254. int curmag = curnode->getMag();
  255. int curcount = curnode->getCount();
  256. while (curmag)
  257. {
  258. chars->push_back(val);
  259. --curmag;
  260. }
  261. while (curcount)
  262. {
  263. int len = chars->size();
  264. for (int i = 0; i < len; i++)
  265. {
  266. cout << (*chars)[i] << " ";
  267. }
  268. cout << endl;
  269. --curcount;
  270. }
  271. for (int i = 0; i < 10; ++i)
  272. {
  273. mainPrint()
  274. }
  275. mainPrint(curnode->getLeft(), chars, 0);
  276. mainPrint(curnode->getRight(), chars, 1);
  277. curmag = curnode->getMag();
  278. while (curmag)
  279. {
  280. chars->pop_back();
  281. --curmag;
  282. }
  283. }
  284. void myPrintIsBetterThanYoursLogan()
  285. {
  286. for (int i = 0; i < 10; ++i)
  287. {
  288. vector<int> * chars = new vector<int>();
  289. mainPrint(nodes[i], chars, i);
  290. delete side;
  291. }
  292. }
  293. int search(vector<int> * val) // val is the string
  294. {
  295. Trienode * curnode;
  296. bool side; // represents if you are on the left or right (right being true)
  297. if ((*val)[0])
  298. {
  299. curnode = right;
  300. side = true;
  301. }
  302. else
  303. {
  304. curnode = left;
  305. side = false;
  306. }
  307. int curmag = curnode->getMag();
  308. for (int i = 0; i < val->size(); i++) // each iteration checks the current character for accuracy. it does not prepare for the next character like the preamble
  309. {
  310. if ((*val)[i]) // if next digit is 1
  311. {
  312. if (side) // if you're on the right
  313. {
  314. if (curmag) // if your current magnitude is >= 1 (still info "left" in this node)
  315. {
  316. --curmag;
  317. continue;
  318. }
  319. if (curnode->getRight()) // If current node is "exhausted", move on to next one
  320. {
  321. curnode = curnode->getRight();
  322. curmag = curnode->getMag() - 1;
  323. continue;
  324. }
  325. else
  326. {
  327. return 0;
  328. }
  329. }
  330. else
  331. {
  332. if (curmag)
  333. {
  334. return 0;
  335. }
  336. if (curnode->getRight())
  337. {
  338. curnode = curnode->getRight();
  339. curmag = curnode->getMag() - 1;
  340. side = true;
  341. continue;
  342. }
  343. else
  344. {
  345. return 0;
  346. }
  347. }
  348. }
  349. else
  350. {
  351. if (!side)
  352. {
  353. if (curmag)
  354. {
  355. --curmag;
  356. continue;
  357. }
  358. if (curnode->getLeft())
  359. {
  360. curnode = curnode->getLeft();
  361. curmag = curnode->getMag() - 1;
  362. continue;
  363. }
  364. else
  365. {
  366. return 0;
  367. }
  368. }
  369. else
  370. {
  371. if (curmag)
  372. {
  373. return 0;
  374. }
  375. if (curnode->getLeft())
  376. {
  377. curnode = curnode->getLeft();
  378. curmag = curnode->getMag() - 1;
  379. side = false;
  380. continue;
  381. }
  382. else
  383. {
  384. return 0;
  385. }
  386. }
  387. }
  388. }
  389. if (!curmag)
  390. {
  391. return curnode->getCount();
  392. }
  393. return 0;
  394. }
  395. void insert(vector<int> * val) // assumes valid input
  396. {
  397. Trienode * curnode; // the node we are checking against our current value
  398. bool side; // represents if you are on the left or right (right being true)
  399. if ((*val)[0])
  400. {
  401. curnode = right;
  402. side = true;
  403. }
  404. else
  405. {
  406. curnode = left;
  407. side = false;
  408. }
  409. int curmag = curnode->getMag(); // "remaining" magnitude of the current node
  410. for (int i = 0; i < val->size(); i++)
  411. {
  412. if ((*val)[i]) // if current digit is 1
  413. {
  414. if (side) // if you're on the right
  415. {
  416. if (curmag) // if your current magnitude is >= 1 (still info "left" in this node)
  417. {
  418. --curmag;
  419. continue;
  420. }
  421. else if (curnode->getRight()) // If current node is "exhausted", move on to next one
  422. {
  423. curnode = curnode->getRight();
  424. curmag = curnode->getMag() - 1;
  425. continue;
  426. }
  427. else if (!(curnode->getLeft()) && !(curnode->getCount())) // if there are no subtrees, just increase this node's magnitude
  428. // also can't do that if the node is flagged, since it needs to retain that info, so check for this
  429. {
  430. curnode->addMag();
  431. continue;
  432. }
  433. else // we're on a "1" node, but it is depleted, and there is a left subtree. so, we create a new node to the right to represent this bit
  434. // also works if the node is flagged and we just need a new node to represent the unflagged set of 1s
  435. {
  436. curnode = curnode->setRight(1, 0);
  437. continue;
  438. }
  439. }
  440. else // we're on a left subtree, but have a 1 coming up
  441. {
  442. if (curmag) // this means we have a value here, so we need to split this node up, branching to the right will be handled by following code
  443. {
  444. Trienode * newnode = new Trienode(0, curnode->getCount()); // this will be the second half of the big node
  445. curnode->zeroCount(); // this and the passing of the count into newnode ensure count is not lost
  446. while (curmag) // fills newnode with the extra magnitude
  447. {
  448. curnode->subMag();
  449. --curmag;
  450. newnode->addMag();
  451. }
  452. newnode->copyLeft(curnode->getLeft()); // move the children to the bottom half
  453. newnode->copyRight(curnode->getRight());
  454. curnode->copyLeft(newnode); // put new node at left of curnode
  455. curnode->copyRight(nullptr); // nothing is in the right yet
  456. goto SKIP1; // skip next if check since we know new right is NULL
  457. }
  458. if (curnode->getRight()) // we can and should move to the right. once there, we sub 1 from magnitude and move on.
  459. {
  460. curnode = curnode->getRight();
  461. curmag = curnode->getMag() - 1;
  462. side = true;
  463. continue;
  464. }
  465. else // we are on left, it is empty, and the right side is empty. create and set that node to curnode->
  466. {
  467. SKIP1:
  468. curnode = curnode->setRight(1, 0);
  469. side = true;
  470. continue;
  471. }
  472. }
  473. }
  474. else // next digit is a 0
  475. {
  476. if (!side) // on a left subtree
  477. {
  478. if (curmag) // still have 0s "remaining" at this node
  479. {
  480. --curmag;
  481. continue;
  482. }
  483. else if (curnode->getLeft()) // no 0s remaining, but there is a left subtree
  484. {
  485. curnode = curnode->getLeft();
  486. curmag = curnode->getMag() - 1;
  487. continue;
  488. }
  489. else if (!(curnode->getRight()) && !(curnode->getCount())) // no subtrees and we're on the correct side, so add to this node's magnitude
  490. // only if this node isn't flagged, since we must retain that info
  491. {
  492. curnode->addMag();
  493. continue;
  494. }
  495. else // no 0s remaining || we are flagged, no left subtree, and we are going to add one.
  496. {
  497. curnode = curnode->setLeft(1, 0);
  498. continue;
  499. }
  500. }
  501. else // we're on a right subtree but have a 0 coming up
  502. {
  503. if (curmag) // this means we have a value here, so we need to split this node up and branch to the left before this point
  504. {
  505. Trienode * newnode = new Trienode(0, curnode->getCount()); // this will be the second half of the big node
  506. curnode->zeroCount(); // This and the passing of getCount to newnode ensure count is not lost
  507. while (curmag) // fills newnode with the extra magnitude
  508. {
  509. curnode->subMag();
  510. --curmag;
  511. newnode->addMag();
  512. }
  513. newnode->copyLeft(curnode->getLeft()); // move the children to the bottom half
  514. newnode->copyRight(curnode->getRight());
  515. curnode->copyLeft(nullptr); // nothing is in the left yet
  516. curnode->copyRight(newnode); // put new node at right of curnode
  517. goto SKIP2; // skip next if check since we know new left is NULL
  518. }
  519. if (curnode->getLeft()) // we can and should move to the left. once there, we sub 1 from magnitude and move on.
  520. {
  521. curnode = curnode->getLeft();
  522. curmag = curnode->getMag() - 1;
  523. side = false;
  524. continue;
  525. }
  526. else // we are on right, it is empty, and the left side is empty. create and set that node to curnode->
  527. {
  528. SKIP2:
  529. curnode = curnode->setLeft(1, 0);
  530. side = false;
  531. continue;
  532. }
  533. }
  534. }
  535. }
  536. // at this point, the node we are at needs to be flagged. However, there is an issue: this node may have magnitude remaining
  537. // if this is the case, we need to split it up at curnode->getMag() - curmag. lets check for the easy case, then proceed
  538. // with that logic if necessary
  539. // basically curmag is our "extra" magnitude that needs to be sent along
  540. if (!curmag)
  541. {
  542. curnode->addCount();
  543. }
  544. else
  545. {
  546. Trienode * newnode = new Trienode(0, curnode->getCount()); // this is our new node, which should retain old flagging
  547. curnode->setCount(1); // curnode will now end where we want to insert, so this should be true
  548. while (curmag) // fills newnode with the extra magnitude
  549. {
  550. curnode->subMag();
  551. --curmag;
  552. newnode->addMag();
  553. }
  554. // now we create the newnode on the appropriate side
  555. newnode->copyLeft(curnode->getLeft());
  556. newnode->copyRight(curnode->getRight());
  557. if (side)
  558. {
  559. curnode->copyLeft(nullptr);
  560. curnode->copyRight(newnode);
  561. }
  562. else
  563. {
  564. curnode->copyLeft(newnode);
  565. curnode->copyRight(nullptr);
  566. }
  567. }
  568. }
  569. void cut(vector<int> * val) // this is delete because i can't use delete :(
  570. {
  571. Trienode * curnode;
  572. Trienode * prevnode = nullptr;
  573. bool side; // represents if you are on the left or right (right being true)
  574. bool side2; // previous node's side
  575. if ((*val)[0])
  576. {
  577. curnode = right;
  578. side = true;
  579. side2 = true;
  580. }
  581. else
  582. {
  583. curnode = left;
  584. side = false;
  585. side2 = false;
  586. }
  587. int curmag = curnode->getMag();
  588. for (int i = 0; i < val->size(); i++) // each iteration checks the current character for accuracy. it does not prepare for the next character like the preamble
  589. {
  590. if ((*val)[i]) // if next digit is 1
  591. {
  592. if (side) // if you're on the right
  593. {
  594. if (curmag) // if your current magnitude is >= 1 (still info "left" in this node)
  595. {
  596. --curmag;
  597. side2 = side;
  598. continue;
  599. }
  600. if (curnode->getRight()) // If current node is "exhausted", move on to next one
  601. {
  602. prevnode = curnode;
  603. curnode = curnode->getRight();
  604. curmag = curnode->getMag() - 1;
  605. side2 = side;
  606. continue;
  607. }
  608. else // node doesn't exist
  609. {
  610. return;
  611. }
  612. }
  613. else
  614. {
  615. if (curmag) // node doesn't exist
  616. {
  617. return;
  618. }
  619. if (curnode->getRight())
  620. {
  621. prevnode = curnode;
  622. curnode = curnode->getRight();
  623. curmag = curnode->getMag() - 1;
  624. side = true;
  625. side2 = false;
  626. continue;
  627. }
  628. else // node doesn't exist
  629. {
  630. return;
  631. }
  632. }
  633. }
  634. else
  635. {
  636. if (!side)
  637. {
  638. if (curmag)
  639. {
  640. --curmag;
  641. side2 = side;
  642. continue;
  643. }
  644. if (curnode->getLeft())
  645. {
  646. prevnode = curnode;
  647. curnode = curnode->getLeft();
  648. curmag = curnode->getMag() - 1;
  649. side2 = side;
  650. continue;
  651. }
  652. else // node doesn't exist
  653. {
  654. return;
  655. }
  656. }
  657. else
  658. {
  659. if (curmag) // node doesn't exist
  660. {
  661. return;
  662. }
  663. if (curnode->getLeft())
  664. {
  665. prevnode = curnode;
  666. curnode = curnode->getLeft();
  667. curmag = curnode->getMag() - 1;
  668. side = false;
  669. side2 = true;
  670. continue;
  671. }
  672. else // node doesn't exist
  673. {
  674. return;
  675. }
  676. }
  677. }
  678. }
  679. // at this point, we have curnode being the "end" of our value
  680. if (!(prevnode)) // if we are deleting one of the 2 base trees
  681. {
  682. if (side)
  683. {
  684. right->subCount();
  685. }
  686. else
  687. {
  688. left->subCount();
  689. }
  690. return;
  691. }
  692. curnode->subCount(); // Normally this is all that is necessary
  693. if (curnode->getCount()) return; // This means we aren't removing a node, so no compression is possible
  694. // Cases where nodes have to be removed/compressed
  695. if (!(curnode->getLeft()) && !(curnode->getRight())) // if our node has no children, destroy it and change parent's reference to NULL
  696. {
  697. if (side)
  698. {
  699. delete curnode;
  700. prevnode->copyRight(nullptr);
  701. }
  702. else
  703. {
  704. delete curnode;
  705. prevnode->copyLeft(nullptr);
  706. }
  707. }
  708. else if (side && curnode->getLeft() && prevnode->getLeft() && side2 && !(prevnode->getCount()) && !(prevnode->getLeft()))
  709. // we are on the right, we have shit to the left, and the parent has nothing to the left, and is not flagged
  710. // this is a rare case where we do have to compress
  711. {
  712. while (curnode->getMag()) // Change mag to parent
  713. {
  714. curnode->subMag();
  715. prevnode->addMag();
  716. }
  717. prevnode->copyLeft(curnode->getLeft()); // Move left side up, delete old data
  718. curnode->copyLeft(nullptr);
  719. prevnode->copyRight(nullptr);
  720. delete curnode;
  721. }
  722. else if (!(side) && curnode->getRight() && prevnode->getRight() && !(side2) && !(prevnode->getCount()) && !(prevnode->getRight()))
  723. // we are on the left, we have shit to the right, and the parent has nothing to the right, and is not flagged
  724. // the same rare case as above
  725. {
  726. while (curnode->getMag()) // Change mag to parent
  727. {
  728. curnode->subMag();
  729. prevnode->addMag();
  730. }
  731. prevnode->copyRight(curnode->getRight()); // Move left side up, delete old data
  732. curnode->copyRight(nullptr);
  733. prevnode->copyLeft(nullptr);
  734. delete curnode;
  735. }
  736. else if (side) // we are on the right and have shit to the right
  737. {
  738. Trienode * child = curnode->getRight();
  739. while (child->getMag()) // moves magnitude from child to parent we are removing
  740. {
  741. child->subMag();
  742. curnode->addMag();
  743. }
  744. curnode->setCount(child->getCount()); // Sets count to child's count
  745. curnode->copyLeft(child->getLeft()); // moves child's children to our parent node
  746. curnode->copyRight(child->getRight());
  747. child->copyLeft(nullptr); // Change child's children to null to allow for safe deletion
  748. child->copyRight(nullptr);
  749. delete child;
  750. }
  751. else // we are on the left and have shit to the left
  752. {
  753. Trienode * child = curnode->getLeft();
  754. while (child->getMag()) // moves magnitude from child to parent we are removing
  755. {
  756. child->subMag();
  757. curnode->addMag();
  758. }
  759. curnode->setCount(child->getCount()); // Sets count to child's count
  760. curnode->copyLeft(child->getLeft()); // moves child's children to our parent node
  761. curnode->copyRight(child->getRight());
  762. child->copyLeft(nullptr); // Change child's children to null to allow for safe deletion
  763. child->copyRight(nullptr);
  764. delete child;
  765. }
  766. }
  767. // update counter with children recursively
  768. void mainCount(Trienode * curnode, int len, int right, int * counter)
  769. {
  770. if (!curnode) return;
  771. len += curnode->getMag();
  772. *counter += (len * curnode->getCount());
  773. mainCount(curnode->getLeft(), len, 0, counter);
  774. mainCount(curnode->getRight(), len, 1, counter);
  775. }
  776. int countChars() // returns total word length of trie
  777. {
  778. int counter = 0;
  779. if (left) mainCount(left, 0, 0, &counter);
  780. if (right) mainCount(right, 0, 1, &counter);
  781. return counter;
  782. }
  783. float compressionovertrie() // returns nodes / nodes in a normal trie
  784. {
  785. float total = left->sumMag() + right->sumMag();
  786. float compressed = left->sumCount() + right->sumCount();
  787. return roundf(compressed/total * 100) / 100;
  788. }
  789. float compressionoverdict() // returns nodes / sum of all word length
  790. {
  791. float compressed = left->sumCount() + right->sumCount();
  792. float total = countChars();
  793. return roundf(compressed/total * 100) / 100;
  794. }
  795. };
  796. #endif