github.com/chain5j/chain5j-pkg@v1.0.7/collection/maps/treemap/README.md (about)

     1  TreeMap v2
     2  ==========
     3  
     4  [![PkgGoDev](https://pkg.go.dev/badge/github.com/igrmk/treemap/v2)](https://pkg.go.dev/github.com/igrmk/treemap/v2)
     5  [![Unlicense](https://img.shields.io/badge/license-Unlicense-brightgreen.svg)](http://unlicense.org/)
     6  [![Build Status](https://api.travis-ci.com/igrmk/treemap.svg?branch=master)](https://app.travis-ci.com/github/igrmk/treemap)
     7  [![Coverage Status](https://coveralls.io/repos/igrmk/treemap/badge.svg?branch=master)](https://coveralls.io/github/igrmk/treemap)
     8  [![GoReportCard](https://goreportcard.com/badge/github.com/igrmk/treemap/v2)](https://goreportcard.com/report/github.com/igrmk/treemap/v2)
     9  [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
    10  
    11  `TreeMap` is a generic key-sorted map using a red-black tree under the hood.
    12  It requires and relies on [Go 1.18](https://tip.golang.org/doc/go1.18) generics feature.
    13  Iterators are designed after C++.
    14  
    15  ### Usage
    16  
    17  ```go
    18  package main
    19  
    20  import (
    21  	"fmt"
    22  
    23  	"github.com/igrmk/treemap/v2"
    24  )
    25  
    26  func main() {
    27  	tr := treemap.New[int, string]()
    28  	tr.Set(1, "World")
    29  	tr.Set(0, "Hello")
    30  	for it := tr.Iterator(); it.Valid(); it.Next() {
    31  		fmt.Println(it.Key(), it.Value())
    32  	}
    33  }
    34  
    35  // Output:
    36  // 0 Hello
    37  // 1 World
    38  ```
    39  
    40  ### Install
    41  
    42  ```bash
    43  go get github.com/igrmk/treemap/v2
    44  ```
    45  
    46  ### Complexity
    47  
    48  |              Name              |   Time    |
    49  |:------------------------------:|:---------:|
    50  |             `Set`              | O(log*N*) |
    51  |             `Del`              | O(log*N*) |
    52  |             `Get`              | O(log*N*) |
    53  |           `Contains`           | O(log*N*) |
    54  |             `Len`              |   O(1)    |
    55  |            `Clear`             |   O(1)    |
    56  |            `Range`             | O(log*N*) |
    57  |           `Iterator`           |   O(1)    |
    58  |           `Reverse`            | O(log*N*) |
    59  | Iterate through the entire map |  O(*N*)   |
    60  
    61  ### Memory usage
    62  
    63  TreeMap uses O(*N*) memory.
    64  
    65  ### TreeMap v1
    66  
    67  The previous version of this package used [gotemplate](https://github.com/ncw/gotemplate) library to generate a type specific file in your local directory.
    68  Here is the link to this version [treemap v1](https://github.com/igrmk/treemap/tree/v1.0.0).
    69  
    70  ### Licensing
    71  
    72  Copyright © 2022 igrmk.
    73  This work is free. You can redistribute it and/or modify it under the
    74  terms of the Unlicense. See the LICENSE file for more details.
    75  
    76  ### Thanks to
    77  
    78  [![JetBrains](svg/jetbrains.svg)](https://www.jetbrains.com/?from=treemap)