github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/database/internal/treap/doc.go (about)

     1  // Copyright (c) 2015-2016 The btcsuite developers
     2  // Copyright (c) 2016 The Dash developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  /*
     7  Package treap implements a treap data structure that is used to hold ordered
     8  key/value pairs using a combination of binary search tree and heap semantics.
     9  It is a self-organizing and randomized data structure that doesn't require
    10  complex operations to to maintain balance.  Search, insert, and delete
    11  operations are all O(log n).  Both mutable and immutable variants are provided.
    12  
    13  The mutable variant is typically faster since it is able to simply update the
    14  treap when modifications are made.  However, a mutable treap is not safe for
    15  concurrent access without careful use of locking by the caller and care must be
    16  taken when iterating since it can change out from under the iterator.
    17  
    18  The immutable variant works by creating a new version of the treap for all
    19  mutations by replacing modified nodes with new nodes that have updated values
    20  while sharing all unmodified nodes with the previous version.  This is extremely
    21  useful in concurrent applications since the caller only has to atomically
    22  replace the treap pointer with the newly returned version after performing any
    23  mutations.  All readers can simply use their existing pointer as a snapshot
    24  since the treap it points to is immutable.  This effectively provides O(1)
    25  snapshot capability with efficient memory usage characteristics since the old
    26  nodes only remain allocated until there are no longer any references to them.
    27  */
    28  package treap