github.com/lbryio/lbcd@v0.22.119/claimtrie/temporal/temporalrepo/memory.go (about)

     1  package temporalrepo
     2  
     3  type Memory struct {
     4  	cache map[int32]map[string]bool
     5  }
     6  
     7  func NewMemory() *Memory {
     8  	return &Memory{
     9  		cache: map[int32]map[string]bool{},
    10  	}
    11  }
    12  
    13  func (repo *Memory) SetNodesAt(names [][]byte, heights []int32) error {
    14  
    15  	for i, height := range heights {
    16  		c, ok := repo.cache[height]
    17  		if !ok {
    18  			c = map[string]bool{}
    19  			repo.cache[height] = c
    20  		}
    21  		name := string(names[i])
    22  		c[name] = true
    23  	}
    24  
    25  	return nil
    26  }
    27  
    28  func (repo *Memory) NodesAt(height int32) ([][]byte, error) {
    29  
    30  	var names [][]byte
    31  
    32  	for name := range repo.cache[height] {
    33  		names = append(names, []byte(name))
    34  	}
    35  
    36  	return names, nil
    37  }
    38  
    39  func (repo *Memory) Close() error {
    40  	return nil
    41  }
    42  
    43  func (repo *Memory) Flush() error {
    44  	return nil
    45  }