AVLMap.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.cast_de_nrw_schule_svws_core_adt_map_AVLMap = exports.AVLMap = void 0;
  4. const JavaMapEntry_1 = require("../../../java/util/JavaMapEntry");
  5. const Comparable_1 = require("../../../java/lang/Comparable");
  6. const AVLMapIntervall_1 = require("../../../core/adt/map/AVLMapIntervall");
  7. const Comparator_1 = require("../../../java/util/Comparator");
  8. const NullPointerException_1 = require("../../../java/lang/NullPointerException");
  9. const AVLMapNode_1 = require("../../../core/adt/map/AVLMapNode");
  10. const ClassCastException_1 = require("../../../java/lang/ClassCastException");
  11. const SortedMap_1 = require("../../../java/util/SortedMap");
  12. const JavaObject_1 = require("../../../java/lang/JavaObject");
  13. const IllegalArgumentException_1 = require("../../../java/lang/IllegalArgumentException");
  14. const NoSuchElementException_1 = require("../../../java/util/NoSuchElementException");
  15. const AVLMapSubMap_1 = require("../../../core/adt/map/AVLMapSubMap");
  16. const UnsupportedOperationException_1 = require("../../../java/lang/UnsupportedOperationException");
  17. class AVLMap extends JavaObject_1.JavaObject {
  18. _infinityMinus = AVLMapIntervall_1.AVLMapIntervall._INFINITY_MINUS;
  19. _infinityPlus = AVLMapIntervall_1.AVLMapIntervall._INFINITY_PLUS;
  20. _dummyValue = new Object();
  21. _sub = new AVLMapSubMap_1.AVLMapSubMap(this, new AVLMapIntervall_1.AVLMapIntervall(this._infinityMinus, false, this._infinityPlus, false), true);
  22. _comparator;
  23. _comparatorNatural = { compare: (key1, key2) => {
  24. if ((key1 === null) || (key2 === null))
  25. throw new NullPointerException_1.NullPointerException();
  26. if (!((((key1 instanceof JavaObject_1.JavaObject) && (key1.isTranspiledInstanceOf('java.lang.Comparable')))) && (((key2 instanceof JavaObject_1.JavaObject) && (key2.isTranspiledInstanceOf('java.lang.Comparable'))))))
  27. throw new ClassCastException_1.ClassCastException();
  28. let k1 = (0, Comparable_1.cast_java_lang_Comparable)(key1);
  29. return k1.compareTo(key2);
  30. } };
  31. _root = null;
  32. _allowKeyAlone = false;
  33. /**
  34. * Implementation for method overloads of 'constructor'
  35. */
  36. constructor(__param0) {
  37. super();
  38. if ((typeof __param0 === "undefined")) {
  39. this._comparator = this._comparatorNatural;
  40. }
  41. else if (((typeof __param0 !== "undefined") && ((typeof __param0 !== 'undefined') && (__param0 instanceof Object) && (__param0 !== null) && ('compare' in __param0) && (typeof __param0.compare === 'function')) || (__param0 === null))) {
  42. let comparator = (0, Comparator_1.cast_java_util_Comparator)(__param0);
  43. this._comparator = comparator;
  44. }
  45. else if (((typeof __param0 !== "undefined") && ((__param0 instanceof JavaObject_1.JavaObject) && (__param0.isTranspiledInstanceOf('java.util.SortedMap'))) || (__param0 === null))) {
  46. let map = (0, SortedMap_1.cast_java_util_SortedMap)(__param0);
  47. this._comparator = (0, Comparator_1.cast_java_util_Comparator)(map.comparator());
  48. this._sub.putAll(map);
  49. }
  50. else
  51. throw new Error('invalid method overload');
  52. }
  53. toString() {
  54. return this._sub.toString();
  55. }
  56. /**
  57. * Bewirkt, dass das Hinzufügen von Keys ohne Value durch {@link AVLMapSubKeySet} erlaubt ist. Die Keys werden
  58. * auf einen Dummy-Wert gemapped.
  59. *
  60. * @param b Falls TRUE, dürfen KEYs ohne VALUE hinzugefügt werden.
  61. */
  62. allowKeyAlone(b) {
  63. this._allowKeyAlone = b;
  64. }
  65. equals(o) {
  66. return JavaObject_1.JavaObject.equalsTranspiler(this._sub, (o));
  67. }
  68. hashCode() {
  69. return JavaObject_1.JavaObject.getTranspilerHashCode(this._sub);
  70. }
  71. comparator() {
  72. return this._sub.comparator();
  73. }
  74. firstKey() {
  75. return this._sub.firstKey();
  76. }
  77. lastKey() {
  78. return this._sub.lastKey();
  79. }
  80. keySet() {
  81. return this._sub.keySet();
  82. }
  83. values() {
  84. return this._sub.values();
  85. }
  86. entrySet() {
  87. return this._sub.entrySet();
  88. }
  89. size() {
  90. return this._sub.size();
  91. }
  92. isEmpty() {
  93. return this._sub.isEmpty();
  94. }
  95. containsKey(key) {
  96. return this._sub.containsKey(key);
  97. }
  98. containsValue(value) {
  99. return this._sub.containsValue(value);
  100. }
  101. get(key) {
  102. return this._sub.get(key);
  103. }
  104. put(key, value) {
  105. return this._sub.put(key, value);
  106. }
  107. remove(key) {
  108. return this._sub.remove(key);
  109. }
  110. putAll(m) {
  111. this._sub.putAll(m);
  112. }
  113. clear() {
  114. this._sub.clear();
  115. }
  116. lowerEntry(key) {
  117. return this._sub.lowerEntry(key);
  118. }
  119. lowerKey(key) {
  120. return this._sub.lowerKey(key);
  121. }
  122. floorEntry(key) {
  123. return this._sub.floorEntry(key);
  124. }
  125. floorKey(key) {
  126. return this._sub.floorKey(key);
  127. }
  128. ceilingEntry(key) {
  129. return this._sub.ceilingEntry(key);
  130. }
  131. ceilingKey(key) {
  132. return this._sub.ceilingKey(key);
  133. }
  134. higherEntry(key) {
  135. return this._sub.higherEntry(key);
  136. }
  137. higherKey(key) {
  138. return this._sub.higherKey(key);
  139. }
  140. firstEntry() {
  141. return this._sub.firstEntry();
  142. }
  143. lastEntry() {
  144. return this._sub.lastEntry();
  145. }
  146. pollFirstEntry() {
  147. return this._sub.pollFirstEntry();
  148. }
  149. pollLastEntry() {
  150. return this._sub.pollLastEntry();
  151. }
  152. descendingMap() {
  153. return this._sub.descendingMap();
  154. }
  155. navigableKeySet() {
  156. return this._sub.navigableKeySet();
  157. }
  158. descendingKeySet() {
  159. return this._sub.descendingKeySet();
  160. }
  161. /**
  162. * Implementation for method overloads of 'subMap'
  163. */
  164. subMap(__param0, __param1, __param2, __param3) {
  165. if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && typeof __param1 === "boolean") && ((typeof __param2 !== "undefined") && (typeof __param2 !== "undefined")) && ((typeof __param3 !== "undefined") && typeof __param3 === "boolean")) {
  166. let fromKey = __param0;
  167. let fromInclusive = __param1;
  168. let toKey = __param2;
  169. let toInclusive = __param3;
  170. return this._sub.subMap(fromKey, fromInclusive, toKey, toInclusive);
  171. }
  172. else if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && (typeof __param1 !== "undefined")) && (typeof __param2 === "undefined") && (typeof __param3 === "undefined")) {
  173. let fromKey = __param0;
  174. let toKey = __param1;
  175. return this._sub.subMap(fromKey, toKey);
  176. }
  177. else
  178. throw new Error('invalid method overload');
  179. }
  180. /**
  181. * Implementation for method overloads of 'headMap'
  182. */
  183. headMap(__param0, __param1) {
  184. if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && typeof __param1 === "boolean")) {
  185. let toKey = __param0;
  186. let inclusive = __param1;
  187. return this._sub.headMap(toKey, inclusive);
  188. }
  189. else if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && (typeof __param1 === "undefined")) {
  190. let toKey = __param0;
  191. return this._sub.headMap(toKey);
  192. }
  193. else
  194. throw new Error('invalid method overload');
  195. }
  196. /**
  197. * Implementation for method overloads of 'tailMap'
  198. */
  199. tailMap(__param0, __param1) {
  200. if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && ((typeof __param1 !== "undefined") && typeof __param1 === "boolean")) {
  201. let fromKey = __param0;
  202. let inclusive = __param1;
  203. return this._sub.tailMap(fromKey, inclusive);
  204. }
  205. else if (((typeof __param0 !== "undefined") && (typeof __param0 !== "undefined")) && (typeof __param1 === "undefined")) {
  206. let fromKey = __param0;
  207. return this._sub.tailMap(fromKey);
  208. }
  209. else
  210. throw new Error('invalid method overload');
  211. }
  212. bcAddEntryReturnBool(e, iv) {
  213. let old = this.bcAddEntryReturnOldValueOrNull(e.getKey(), e.getValue(), iv);
  214. return !this._valEquals(old, e.getValue());
  215. }
  216. bcAddAllEntries(c, iv) {
  217. let changed = false;
  218. for (let entry of c)
  219. changed = changed || this.bcAddEntryReturnBool(entry, iv);
  220. return changed;
  221. }
  222. bcAddEntryReturnOldValueOrNull(key, value, iv) {
  223. if (key === null)
  224. throw new NullPointerException_1.NullPointerException("TreeMap erlaubt keine NULL keys.");
  225. if (this._isOutOfRange(key, iv))
  226. throw new IllegalArgumentException_1.IllegalArgumentException("Der Schlüsselwert liegt nicht im gültigen Bereich.");
  227. if (this._root === null) {
  228. this._root = new AVLMapNode_1.AVLMapNode(key, value);
  229. return null;
  230. }
  231. let node = this._nodeGetOrNull(key, iv);
  232. let old = (node === null) ? null : node._val;
  233. this._root = this._nodePutRecursive(this._root, key, value);
  234. return old;
  235. }
  236. bcAddValue(e, iv) {
  237. throw new UnsupportedOperationException_1.UnsupportedOperationException();
  238. }
  239. bcAddKey(e, iv) {
  240. if (this._allowKeyAlone === false)
  241. throw new UnsupportedOperationException_1.UnsupportedOperationException();
  242. if (this.bcContainsKey(e, iv))
  243. return false;
  244. this.bcAddEntryReturnOldValueOrNull(e, this._dummyValue, iv);
  245. return true;
  246. }
  247. bcAddAllKeys(c, iv) {
  248. let changed = false;
  249. for (let key of c)
  250. changed = changed || this.bcAddKey(key, iv);
  251. return changed;
  252. }
  253. bcAddAllEntriesOfMap(map, iv) {
  254. for (let entry of map.entrySet())
  255. this.bcAddEntryReturnOldValueOrNull(entry.getKey(), entry.getValue(), iv);
  256. }
  257. bcContainsKey(objKey, iv) {
  258. return this._nodeGetOrNull(objKey, iv) !== null;
  259. }
  260. bcContainsAllKeys(c, iv) {
  261. for (let key of c)
  262. if (!this.bcContainsKey(key, iv))
  263. return false;
  264. return true;
  265. }
  266. bcContainsValue(objValue, iv) {
  267. let value = objValue;
  268. let n1 = this._nodeFirstOrNull(iv);
  269. if (n1 === null)
  270. return false;
  271. let n2 = this._nodeLastOrNull(iv);
  272. if (n2 === null)
  273. return false;
  274. while (n1 !== n2) {
  275. if (n1 === null)
  276. throw new NullPointerException_1.NullPointerException();
  277. if (this._valEquals(n1._val, value))
  278. return true;
  279. n1 = n1._next;
  280. }
  281. return this._valEquals(n2._val, value);
  282. }
  283. bcContainsAllValues(col, iv) {
  284. for (let val of col)
  285. if (!this.bcContainsValue(val, iv))
  286. return false;
  287. return true;
  288. }
  289. bcContainsEntry(o, iv) {
  290. if (((o instanceof JavaObject_1.JavaObject) && (o.isTranspiledInstanceOf('java.util.Map.Entry'))) === false)
  291. return false;
  292. let e = (0, JavaMapEntry_1.cast_java_util_Map_Entry)(o);
  293. let node = this._nodeGetOrNull(e.getKey(), iv);
  294. return (node === null) ? false : this._valEquals(node._val, e.getValue());
  295. }
  296. bcContainsAllEntries(c, iv) {
  297. for (let entry of c)
  298. if (!this.bcContainsEntry(entry, iv))
  299. return false;
  300. return true;
  301. }
  302. bcRemoveKeyReturnBool(o, iv) {
  303. if (!this.bcContainsKey(o, iv))
  304. return false;
  305. this.bcRemoveKeyReturnOldValueOrNull(o, iv);
  306. return true;
  307. }
  308. bcRemoveAllKeys(c, iv) {
  309. let changed = false;
  310. for (let obj of c)
  311. changed = changed || this.bcRemoveKeyReturnBool(obj, iv);
  312. return changed;
  313. }
  314. bcRemoveEntry(o, iv) {
  315. if (!this.bcContainsEntry(o, iv))
  316. return false;
  317. if (((o instanceof JavaObject_1.JavaObject) && (o.isTranspiledInstanceOf('java.util.Map.Entry'))) === false)
  318. return false;
  319. if (this._root === null)
  320. throw new NullPointerException_1.NullPointerException();
  321. let e = (0, JavaMapEntry_1.cast_java_util_Map_Entry)(o);
  322. this._root = this._nodeRemoveKeyRecursive(this._root, e.getKey());
  323. return true;
  324. }
  325. bcRemoveAllEntries(c, iv) {
  326. let removedAny = false;
  327. for (let entry of c)
  328. removedAny = removedAny || this.bcRemoveEntry(entry, iv);
  329. return removedAny;
  330. }
  331. bcRemoveKeyReturnOldValueOrNull(obj, iv) {
  332. if (obj === null)
  333. throw new NullPointerException_1.NullPointerException("TreeMap unterstützt keine NULL-Schlüssel.");
  334. let key = obj;
  335. let old = this._nodeGetOrNull(key, iv);
  336. if (old === null)
  337. return null;
  338. if (this._root === null)
  339. throw new NullPointerException_1.NullPointerException();
  340. this._root = this._nodeRemoveKeyRecursive(this._root, key);
  341. return old._val;
  342. }
  343. bcPollFirstEntryOrNull(iv) {
  344. let node = this._nodeFirstOrNull(iv);
  345. if (node === null)
  346. return node;
  347. if (this._root === null)
  348. throw new NullPointerException_1.NullPointerException();
  349. this._root = this._nodeRemoveKeyRecursive(this._root, node._key);
  350. return node;
  351. }
  352. bcPollFirstKeyOrNull(iv) {
  353. let node = this._nodeFirstOrNull(iv);
  354. if (node === null)
  355. return null;
  356. if (this._root === null)
  357. throw new NullPointerException_1.NullPointerException();
  358. this._root = this._nodeRemoveKeyRecursive(this._root, node._key);
  359. return node._key;
  360. }
  361. bcPollLastEntryOrNull(iv) {
  362. let node = this._nodeLastOrNull(iv);
  363. if (node === null)
  364. return null;
  365. if (this._root === null)
  366. throw new NullPointerException_1.NullPointerException();
  367. this._root = this._nodeRemoveKeyRecursive(this._root, node._key);
  368. return node;
  369. }
  370. bcPollLastKeyOrNull(iv) {
  371. let node = this._nodeLastOrNull(iv);
  372. if (node === null)
  373. return null;
  374. if (this._root === null)
  375. throw new NullPointerException_1.NullPointerException();
  376. this._root = this._nodeRemoveKeyRecursive(this._root, node._key);
  377. return node._key;
  378. }
  379. bcIsEmpty(iv) {
  380. return this._nodeFirstOrNull(iv) === null;
  381. }
  382. bcGetComparator(iv) {
  383. return this._comparator;
  384. }
  385. bcGetFirstKeyOrException(iv) {
  386. return this._keyOrExeption(this._nodeFirstOrNull(iv));
  387. }
  388. bcGetFirstEntryOrNull(iv) {
  389. return this._nodeFirstOrNull(iv);
  390. }
  391. bcGetLastKeyOrException(iv) {
  392. return this._keyOrExeption(this._nodeLastOrNull(iv));
  393. }
  394. bcGetLastEntryOrNull(iv) {
  395. return this._nodeLastOrNull(iv);
  396. }
  397. bcGetNextEntryOrNull(current, iv) {
  398. return this._nodeNextOrNull(current, iv);
  399. }
  400. bcGetPrevEntryOrNull(current, iv) {
  401. return this._nodePrevOrNull(current, iv);
  402. }
  403. bcGetSize(iv) {
  404. let n1 = this._nodeFirstOrNull(iv);
  405. if (n1 === null)
  406. return 0;
  407. let n2 = this._nodeLastOrNull(iv);
  408. if (n2 === null)
  409. return 0;
  410. return this._nodeIndexOf(n2._key) - this._nodeIndexOf(n1._key) + 1;
  411. }
  412. bcGetValueOfKeyOrNull(objKey, iv) {
  413. let key = objKey;
  414. let node = this._nodeGetOrNull(key, iv);
  415. return (node === null) ? null : node._val;
  416. }
  417. bcGetLowerEntryOrNull(key, iv) {
  418. return this._nodeLowerOrNull(key, iv);
  419. }
  420. bcGetLowerKeyOrNull(key, iv) {
  421. return this._keyOrNull(this._nodeLowerOrNull(key, iv));
  422. }
  423. bcGetFloorEntryOrNull(key, iv) {
  424. return this._nodeFloorOrNull(key, iv);
  425. }
  426. bcGetFloorKeyOrNull(key, iv) {
  427. return this._keyOrNull(this._nodeFloorOrNull(key, iv));
  428. }
  429. bcGetCeilingEntryOrNull(key, iv) {
  430. return this._nodeCeilingOrNull(key, iv);
  431. }
  432. bcGetCeilingKeyOrNull(key, iv) {
  433. return this._keyOrNull(this._nodeCeilingOrNull(key, iv));
  434. }
  435. bcGetHigherEntryOrNull(key, iv) {
  436. return this._nodeHigherOrNull(key, iv);
  437. }
  438. bcGetHigherKeyOrNull(key, iv) {
  439. return this._keyOrNull(this._nodeHigherOrNull(key, iv));
  440. }
  441. bcCheckOutOfIntervall(key, inc, iv) {
  442. if ((key === this._infinityMinus) || (key === this._infinityPlus))
  443. return false;
  444. let cmpF = this._compare(key, iv.from);
  445. if (cmpF < 0)
  446. return true;
  447. if ((cmpF === 0) && (!iv.fromInc) && (inc))
  448. return true;
  449. let cmpT = this._compare(key, iv.to);
  450. if (cmpT > 0)
  451. return true;
  452. if ((cmpT === 0) && (!iv.toInc) && (inc))
  453. return true;
  454. return false;
  455. }
  456. _keyOrNull(node) {
  457. return (node === null) ? null : node._key;
  458. }
  459. _valEquals(v1, v2) {
  460. return (v1 === null) ? v2 === null : JavaObject_1.JavaObject.equalsTranspiler(v1, (v2));
  461. }
  462. _keyOrExeption(node) {
  463. if (node === null)
  464. throw new NoSuchElementException_1.NoSuchElementException();
  465. return node._key;
  466. }
  467. _compare(key1, key2) {
  468. if ((key1 === this._infinityMinus) || (key2 === this._infinityPlus))
  469. return -1;
  470. if ((key1 === this._infinityPlus) || (key2 === this._infinityMinus))
  471. return +1;
  472. return this._comparator.compare(key1, key2);
  473. }
  474. _isOutOfRange(key, iv) {
  475. let cmpKeyFrom = this._compare(key, iv.from);
  476. if ((cmpKeyFrom < 0) || (cmpKeyFrom === 0) && (!iv.fromInc))
  477. return true;
  478. let cmpKeyTo = this._compare(key, iv.to);
  479. if ((cmpKeyTo > 0) || (cmpKeyTo === 0) && (!iv.toInc))
  480. return true;
  481. return false;
  482. }
  483. _nodeFirstOrNull(iv) {
  484. return iv.fromInc ? this._nodeCeilingOrNull(iv.from, iv) : this._nodeHigherOrNull(iv.from, iv);
  485. }
  486. _nodeLastOrNull(iv) {
  487. return iv.toInc ? this._nodeFloorOrNull(iv.to, iv) : this._nodeLowerOrNull(iv.to, iv);
  488. }
  489. _nodeCeilingOrNull(key, iv) {
  490. let node = this._nodeDeepestOrNull(key, iv);
  491. if (node === null)
  492. return null;
  493. let cmpNodeKey = this._compare(node._key, key);
  494. return cmpNodeKey >= 0 ? node : this._nodeNextOrNull(node, iv);
  495. }
  496. _nodeHigherOrNull(key, iv) {
  497. let node = this._nodeDeepestOrNull(key, iv);
  498. if (node === null)
  499. return null;
  500. let cmpNodeKey = this._compare(node._key, key);
  501. return cmpNodeKey > 0 ? node : this._nodeNextOrNull(node, iv);
  502. }
  503. _nodeFloorOrNull(key, iv) {
  504. let node = this._nodeDeepestOrNull(key, iv);
  505. if (node === null)
  506. return null;
  507. let cmpNodeKey = this._compare(node._key, key);
  508. return cmpNodeKey <= 0 ? node : this._nodePrevOrNull(node, iv);
  509. }
  510. _nodeLowerOrNull(key, iv) {
  511. let node = this._nodeDeepestOrNull(key, iv);
  512. if (node === null)
  513. return null;
  514. let cmpNodeKey = this._compare(node._key, key);
  515. return cmpNodeKey < 0 ? node : this._nodePrevOrNull(node, iv);
  516. }
  517. _nodeNextOrNull(node, iv) {
  518. let next = node._next;
  519. return (next === null) ? null : this._isOutOfRange(next._key, iv) ? null : next;
  520. }
  521. _nodePrevOrNull(node, iv) {
  522. let prev = node._prev;
  523. return (prev === null) ? null : this._isOutOfRange(prev._key, iv) ? null : prev;
  524. }
  525. _nodeGetOrNull(key, iv) {
  526. let node = this._nodeDeepestOrNull(key, iv);
  527. if (node === null)
  528. return null;
  529. return this._compare(key, node._key) === 0 ? node : null;
  530. }
  531. _nodeIndexOf(key) {
  532. let current = this._root;
  533. let index = 0;
  534. while (true) {
  535. if (current === null)
  536. throw new NullPointerException_1.NullPointerException();
  537. let cmp = this._compare(key, current._key);
  538. if (cmp < 0) {
  539. current = current._childL;
  540. continue;
  541. }
  542. let left = current._childL;
  543. let sizeL = (left === null) ? 0 : left._size;
  544. if (cmp > 0) {
  545. index += sizeL + 1;
  546. current = current._childR;
  547. continue;
  548. }
  549. return index + sizeL;
  550. }
  551. }
  552. _nodeDeepestOrNull(key, iv) {
  553. let current = this._root;
  554. let last = null;
  555. while (current !== null) {
  556. let cmpToKey = this._compare(iv.to, current._key);
  557. if ((cmpToKey < 0) || (cmpToKey === 0) && (!iv.toInc)) {
  558. current = current._childL;
  559. continue;
  560. }
  561. let cmpFromKey = this._compare(iv.from, current._key);
  562. if ((cmpFromKey > 0) || (cmpFromKey === 0) && (!iv.fromInc)) {
  563. current = current._childR;
  564. continue;
  565. }
  566. last = current;
  567. let cmp = this._compare(key, current._key);
  568. if (cmp < 0) {
  569. current = current._childL;
  570. continue;
  571. }
  572. if (cmp > 0) {
  573. current = current._childR;
  574. continue;
  575. }
  576. return current;
  577. }
  578. return last;
  579. }
  580. _nodePutRecursive(current, key, value) {
  581. let cmp = this._compare(key, current._key);
  582. if (cmp === 0) {
  583. current._val = value;
  584. return current;
  585. }
  586. if (cmp < 0)
  587. current._childL = (current._childL === null) ? this._nodeCreateLeaf(current._prev, current, key, value) : this._nodePutRecursive(current._childL, key, value);
  588. else
  589. current._childR = (current._childR === null) ? this._nodeCreateLeaf(current, current._next, key, value) : this._nodePutRecursive(current._childR, key, value);
  590. return this._nodeRevalidate(current);
  591. }
  592. _nodeCreateLeaf(prev, next, key, value) {
  593. let child = new AVLMapNode_1.AVLMapNode(key, value);
  594. if (prev !== null) {
  595. prev._next = child;
  596. child._prev = prev;
  597. }
  598. if (next !== null) {
  599. next._prev = child;
  600. child._next = next;
  601. }
  602. return child;
  603. }
  604. _nodeRemoveKeyRecursive(current, key) {
  605. let cmp = this._compare(key, current._key);
  606. if (cmp < 0) {
  607. if (current._childL === null)
  608. throw new NullPointerException_1.NullPointerException();
  609. current._childL = this._nodeRemoveKeyRecursive(current._childL, key);
  610. return this._nodeRevalidate(current);
  611. }
  612. if (cmp > 0) {
  613. if (current._childR === null)
  614. throw new NullPointerException_1.NullPointerException();
  615. current._childR = this._nodeRemoveKeyRecursive(current._childR, key);
  616. return this._nodeRevalidate(current);
  617. }
  618. if (current._childL === null) {
  619. this._nodeRemovePrevNext(current);
  620. return current._childR;
  621. }
  622. if (current._childR === null) {
  623. this._nodeRemovePrevNext(current);
  624. return current._childL;
  625. }
  626. let next = current._next;
  627. if (next === null)
  628. throw new NullPointerException_1.NullPointerException();
  629. current._childR = this._nodeRemoveKeyRecursive(current._childR, next._key);
  630. return this._nodeRevalidate(this._nodeReplaceReferencesFromAwithB(next, current));
  631. }
  632. _nodeReplaceReferencesFromAwithB(a, b) {
  633. a._childL = b._childL;
  634. a._childR = b._childR;
  635. let p = b._prev;
  636. let n = b._next;
  637. a._prev = p;
  638. a._next = n;
  639. if (p !== null)
  640. p._next = a;
  641. if (n !== null)
  642. n._prev = a;
  643. return a;
  644. }
  645. _nodeRemovePrevNext(current) {
  646. let nodeP = current._prev;
  647. let nodeN = current._next;
  648. if (nodeP !== null)
  649. nodeP._next = nodeN;
  650. if (nodeN !== null)
  651. nodeN._prev = nodeP;
  652. }
  653. /**
  654. * Aktualisiert {@code node} und liefert, wenn es zur Rotation kommt, eine neue Sub-Wurzel.
  655. *
  656. * @param node Der Knoten, der revalidiert werden soll.
  657. *
  658. * @return node, oder die neue Sub-Wurzel, wenn es zur Rotation kam.
  659. */
  660. _nodeRevalidate(node) {
  661. let heightBalance = this._nodeGetHeightBalance(node);
  662. if (heightBalance > +1) {
  663. if (node._childR === null)
  664. throw new NullPointerException_1.NullPointerException();
  665. if (this._nodeGetHeightBalance(node._childR) < 0)
  666. node._childR = this._nodeRotateRight(node._childR);
  667. return this._nodeRotateLeft(node);
  668. }
  669. if (heightBalance < -1) {
  670. if (node._childL === null)
  671. throw new NullPointerException_1.NullPointerException();
  672. if (this._nodeGetHeightBalance(node._childL) > 0)
  673. node._childL = this._nodeRotateLeft(node._childL);
  674. return this._nodeRotateRight(node);
  675. }
  676. this._nodeRevalidateHeightAndSize(node);
  677. return node;
  678. }
  679. _nodeRotateLeft(nodeM) {
  680. if (nodeM._childR === null)
  681. throw new NullPointerException_1.NullPointerException();
  682. let nodeR = nodeM._childR;
  683. nodeM._childR = nodeR._childL;
  684. nodeR._childL = nodeM;
  685. this._nodeRevalidateHeightAndSize(nodeM);
  686. this._nodeRevalidateHeightAndSize(nodeR);
  687. return nodeR;
  688. }
  689. _nodeRotateRight(nodeM) {
  690. if (nodeM._childL === null)
  691. throw new NullPointerException_1.NullPointerException();
  692. let nodeL = nodeM._childL;
  693. nodeM._childL = nodeL._childR;
  694. nodeL._childR = nodeM;
  695. this._nodeRevalidateHeightAndSize(nodeM);
  696. this._nodeRevalidateHeightAndSize(nodeL);
  697. return nodeL;
  698. }
  699. _nodeRevalidateHeightAndSize(node) {
  700. let sizeL = (node._childL === null) ? 0 : node._childL._size;
  701. let sizeR = (node._childR === null) ? 0 : node._childR._size;
  702. node._size = sizeL + sizeR + 1;
  703. let heightL = (node._childL === null) ? 0 : node._childL._height;
  704. let heightR = (node._childR === null) ? 0 : node._childR._height;
  705. node._height = Math.max(heightL, heightR) + 1;
  706. }
  707. _nodeGetHeightBalance(node) {
  708. let heightL = (node._childL === null) ? 0 : node._childL._height;
  709. let heightR = (node._childR === null) ? 0 : node._childR._height;
  710. return heightR - heightL;
  711. }
  712. isTranspiledInstanceOf(name) {
  713. return ['java.util.Map', 'de.nrw.schule.svws.core.adt.map.AVLMap', 'java.util.NavigableMap', 'java.util.SortedMap'].includes(name);
  714. }
  715. }
  716. exports.AVLMap = AVLMap;
  717. function cast_de_nrw_schule_svws_core_adt_map_AVLMap(obj) {
  718. return obj;
  719. }
  720. exports.cast_de_nrw_schule_svws_core_adt_map_AVLMap = cast_de_nrw_schule_svws_core_adt_map_AVLMap;
  721. //# sourceMappingURL=AVLMap.js.map