-
Notifications
You must be signed in to change notification settings - Fork 0
/
2e501da1.767ceecc.js
1 lines (1 loc) · 4.63 KB
/
2e501da1.767ceecc.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[14],{147:function(e,t,n){"use strict";function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}n.d(t,"a",(function(){return r}))},148:function(e,t,n){"use strict";n.d(t,"a",(function(){return s})),n.d(t,"b",(function(){return m}));var r=n(0),a=n.n(r);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var u=a.a.createContext({}),l=function(e){var t=a.a.useContext(u),n=t;return e&&(n="function"==typeof e?e(t):p(p({},t),e)),n},s=function(e){var t=l(e.components);return a.a.createElement(u.Provider,{value:t},e.children)},b={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},f=a.a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,c=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),s=l(n),f=r,m=s["".concat(c,".").concat(f)]||s[f]||b[f]||o;return n?a.a.createElement(m,p(p({ref:t},u),{},{components:n})):a.a.createElement(m,p({ref:t},u))}));function m(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,c=new Array(o);c[0]=f;var p={};for(var i in t)hasOwnProperty.call(t,i)&&(p[i]=t[i]);p.originalType=e,p.mdxType="string"==typeof e?e:r,c[1]=p;for(var u=2;u<o;u++)c[u]=n[u];return a.a.createElement.apply(null,c)}return a.a.createElement.apply(null,n)}f.displayName="MDXCreateElement"},149:function(e,t,n){"use strict";function r(e,t){if(null==e)return{};var n,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}n.d(t,"a",(function(){return r}))},89:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return c})),n.d(t,"metadata",(function(){return p})),n.d(t,"toc",(function(){return i})),n.d(t,"default",(function(){return l}));var r=n(147),a=n(149),o=(n(0),n(148)),c={id:"TreeMap",title:"TreeMap",sidebar_label:"TreeMap"},p={unversionedId:"Language/Java/Map/TreeMap",id:"Language/Java/Map/TreeMap",isDocsHomePage:!1,title:"TreeMap",description:"Basics",source:"@site/docs/Language/Java/Map/TreeMap.md",slug:"/Language/Java/Map/TreeMap",permalink:"/docs/Language/Java/Map/TreeMap",version:"current",sidebar_label:"TreeMap",sidebar:"Language",previous:{title:"HashTable",permalink:"/docs/Language/Java/Map/HashTable"},next:{title:"LinkedHashMap",permalink:"/docs/Language/Java/Map/LinkedHashMap"}},i=[{value:"Basics",id:"basics",children:[]},{value:"TreeMap vs HashMap",id:"treemap-vs-hashmap",children:[]}],u={toc:i};function l(e){var t=e.components,n=Object(a.a)(e,["components"]);return Object(o.b)("wrapper",Object(r.a)({},u,n,{components:t,mdxType:"MDXLayout"}),Object(o.b)("h2",{id:"basics"},"Basics"),Object(o.b)("ul",null,Object(o.b)("li",{parentName:"ul"},"TreeMap is ordered by Keys"),Object(o.b)("li",{parentName:"ul"},"put(), get(), remove() all cost O(logN) in the worst scenario"),Object(o.b)("li",{parentName:"ul"},"Iteration order predictable"),Object(o.b)("li",{parentName:"ul"},"Allows only Values to be null, Keys cannot be null")),Object(o.b)("h2",{id:"treemap-vs-hashmap"},"TreeMap vs HashMap"),Object(o.b)("ul",null,Object(o.b)("li",{parentName:"ul"},"TreeMap are naturally sorted by order of key, HashMap is not:")),Object(o.b)("pre",null,Object(o.b)("code",Object(r.a)({parentName:"pre"},{}),"TreeMap<Integer, Integer> tm = new TreeMap<>();\ntm.put(3, 1);\ntm.put(2, 2);\ntm.put(1, 10);\ntm.put(-100, 2);\ntm.values(); //[2, 10, 2, 1]\n\nHashMap<Integer, Integer> hm = new HashMap<>();\nhm.put(3, 1);\nhm.put(2, 2);\nhm.put(1, 10);\nhm.put(-100, 2);\nhm.values(); // [10, 2, 1, 2]\n")))}l.isMDXComponent=!0}}]);