{"id":19267022,"url":"https://github.com/mljs/tree-set","last_synced_at":"2025-04-21T19:32:31.538Z","repository":{"id":57299008,"uuid":"67320664","full_name":"mljs/tree-set","owner":"mljs","description":"A JavaScript emulator of  the TreeSet Java class","archived":false,"fork":false,"pushed_at":"2016-11-23T21:25:47.000Z","size":5,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-01T15:41:57.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-04T02:01:36.000Z","updated_at":"2024-01-09T13:13:15.000Z","dependencies_parsed_at":"2022-08-26T18:12:42.103Z","dependency_job_id":null,"html_url":"https://github.com/mljs/tree-set","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ftree-set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ftree-set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ftree-set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Ftree-set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/tree-set/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250120079,"owners_count":21378135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T20:09:28.388Z","updated_at":"2025-04-21T19:32:31.532Z","avatar_url":"https://github.com/mljs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tree-set\n\n  [![NPM version][npm-image]][npm-url]\n  [![build status][travis-image]][travis-url]\n  [![David deps][david-image]][david-url]\n  [![npm download][download-image]][download-url]\n  \nA JavaScript emulator of the TreeSet Java class\n\n## Installation\n\n```\n$ npm install ml-tree-set\n```\n\n## Documentation\n\nTreeSet allows to create a sorted array of objects by adding each new element in order, according with the comparator` function`.\nTreeSet does not really implements a tree to maintain the order. It just add the elements in the correct place in the array. \nNevertheless adding, removing or finding an element is guaranteed to be performed in log(n).\n\nUnlike the other binary-tree implementations available in npm, this one allows repeated keys.\n\n\n###constructor(comparator): \n\nCreate a new TreeSet object. The comparator gives the order to the set. By default it is the natural comparator\n\n```\nfunction(a, b){ return a - b };\n```\n\n### add(element): \n\nAdd an element to the sorted list\n\n### size(): \n\nReturn the number of elements in the set\n\n### last(): \n\nReturn the last element of the sorted list\n\n### first(): \n\nReturn the first element of the sorted list\n\n### pollLast(): \n\nReturn and removes the last element of the sorted list\n\n### pollFirst(): \n\nReturn and removes the first element of the sorted list\n\n### binarySearch(element): \n\nPerforms a binary search of value in array\n\n##Example\n\n```js\n const myList = new TreeSet(function( a, b){ return a.index - b.index; });\n myList.add({index:0,value:\"a\"});\n myList.add({index:3,value:\"d\"});\n myList.add({index:2,value:\"c\"});\n myList.pollFirst();\n myList.add({index:1,value:\"b\"});\n //The myList.elements should be: [{index:1,value:\"b\"},{index:2,value:\"c\"},{index:3,value:\"d\"}]);\n //myList.size() should be equal to 3;\n```\n\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-tree-set.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-tree-set\n[travis-image]: https://img.shields.io/travis/mljs/tree-set/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mljs/tree-set\n[david-image]: https://img.shields.io/david/mljs/tree-set.svg?style=flat-square\n[david-url]: https://david-dm.org/mljs/tree-set\n[download-image]: https://img.shields.io/npm/dm/ml-tree-set.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-tree-set\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Ftree-set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Ftree-set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Ftree-set/lists"}