https://github.com/chpengzh/avl-treemap
A TreeMap implement by AVL Algorithm
https://github.com/chpengzh/avl-treemap
Last synced: 2 months ago
JSON representation
A TreeMap implement by AVL Algorithm
- Host: GitHub
- URL: https://github.com/chpengzh/avl-treemap
- Owner: chpengzh
- Created: 2017-12-03T14:35:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-03T14:55:57.000Z (about 8 years ago)
- Last Synced: 2024-12-27T06:41:47.821Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AVLTreeMap
## What is AVL?
you can find the definition of AVLTree in [Wiki](https://en.wikipedia.org/wiki/AVL_tree)
## Basic Use
`AVLTreeMap` implements interface `Map`
so you can use it as a single map
and of course, it is `thread safe`
> Insert or Update
```java
map.put(someKey, someValue);
```
> Atomic value combination
```
map.put(someKey, (old) -> {
if (old == null) {
return someValue
} else {
return doSomeThing(someValue, old)
}
})
```
> Page Query with offset and limit (Just like `java.util.TreeMap` which is implements by Red Black Tree)
```
//query top n
LinkedHashMap result = map.max(offset, limit);
//query last n
LinkedHashMap result = map.min(offset, limit)
```