github.com/renegr87/renegr87@v2.1.1+incompatible/core/ledger/kvledger/txmgmt/pvtstatepurgemgmt/pvtdata_key_helper.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package pvtstatepurgemgmt
     8  
     9  func (pvtdataKeys *PvtdataKeys) addAll(toAdd *PvtdataKeys) {
    10  	for ns, colls := range toAdd.Map {
    11  		for coll, keysAndHashes := range colls.Map {
    12  			for _, k := range keysAndHashes.List {
    13  				pvtdataKeys.add(ns, coll, k.Key, k.Hash)
    14  			}
    15  		}
    16  	}
    17  }
    18  
    19  func (pvtdataKeys *PvtdataKeys) add(ns string, coll string, key string, keyhash []byte) {
    20  	colls := pvtdataKeys.getOrCreateCollections(ns)
    21  	keysAndHashes := colls.getOrCreateKeysAndHashes(coll)
    22  	keysAndHashes.List = append(keysAndHashes.List, &KeyAndHash{Key: key, Hash: keyhash})
    23  }
    24  
    25  func (pvtdataKeys *PvtdataKeys) getOrCreateCollections(ns string) *Collections {
    26  	colls, ok := pvtdataKeys.Map[ns]
    27  	if !ok {
    28  		colls = newCollections()
    29  		pvtdataKeys.Map[ns] = colls
    30  	}
    31  	return colls
    32  }
    33  
    34  func (colls *Collections) getOrCreateKeysAndHashes(coll string) *KeysAndHashes {
    35  	keysAndHashes, ok := colls.Map[coll]
    36  	if !ok {
    37  		keysAndHashes = &KeysAndHashes{}
    38  		colls.Map[coll] = keysAndHashes
    39  	}
    40  	return keysAndHashes
    41  }
    42  
    43  func newPvtdataKeys() *PvtdataKeys {
    44  	return &PvtdataKeys{Map: make(map[string]*Collections)}
    45  }
    46  
    47  func newCollections() *Collections {
    48  	return &Collections{Map: make(map[string]*KeysAndHashes)}
    49  }