github.com/lbryio/lbcd@v0.22.119/database/internal/treap/README.md (about)

     1  treap
     2  =====
     3  
     4  [![Build Status](https://github.com/lbryio/lbcd/workflows/Build%20and%20Test/badge.svg)](https://github.com/lbryio/lbcd/actions)
     5  [![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
     6  [![GoDoc](https://pkg.go.dev/github.com/lbryio/lbcd/database/internal/treap?status.png)](https://pkg.go.dev/github.com/lbryio/lbcd/database/internal/treap)
     7  
     8  Package treap implements a treap data structure that is used to hold ordered
     9  key/value pairs using a combination of binary search tree and heap semantics.
    10  It is a self-organizing and randomized data structure that doesn't require
    11  complex operations to maintain balance.  Search, insert, and delete
    12  operations are all O(log n).  Both mutable and immutable variants are provided.
    13  
    14  The mutable variant is typically faster since it is able to simply update the
    15  treap when modifications are made.  However, a mutable treap is not safe for
    16  concurrent access without careful use of locking by the caller and care must be
    17  taken when iterating since it can change out from under the iterator.
    18  
    19  The immutable variant works by creating a new version of the treap for all
    20  mutations by replacing modified nodes with new nodes that have updated values
    21  while sharing all unmodified nodes with the previous version.  This is extremely
    22  useful in concurrent applications since the caller only has to atomically
    23  replace the treap pointer with the newly returned version after performing any
    24  mutations.  All readers can simply use their existing pointer as a snapshot
    25  since the treap it points to is immutable.  This effectively provides O(1)
    26  snapshot capability with efficient memory usage characteristics since the old
    27  nodes only remain allocated until there are no longer any references to them.
    28  
    29  Package treap is licensed under the copyfree ISC license.
    30  
    31  ## Usage
    32  
    33  This package is only used internally in the database code and as such is not
    34  available for use outside of it.
    35  
    36  ## License
    37  
    38  Package treap is licensed under the [copyfree](http://copyfree.org) ISC
    39  License.