github.com/attic-labs/noms@v0.0.0-20210827224422-e5fa29d95e8b/go/hash/hash_slice.go (about)

     1  // Copyright 2016 Attic Labs, Inc. All rights reserved.
     2  // Licensed under the Apache License, version 2.0:
     3  // http://www.apache.org/licenses/LICENSE-2.0
     4  
     5  package hash
     6  
     7  type HashSlice []Hash
     8  
     9  func (rs HashSlice) Len() int {
    10  	return len(rs)
    11  }
    12  
    13  func (rs HashSlice) Less(i, j int) bool {
    14  	return rs[i].Less(rs[j])
    15  }
    16  
    17  func (rs HashSlice) Swap(i, j int) {
    18  	rs[i], rs[j] = rs[j], rs[i]
    19  }
    20  
    21  func (rs HashSlice) Equals(other HashSlice) bool {
    22  	if len(rs) != len(other) {
    23  		return false
    24  	}
    25  	for i := 0; i < len(rs); i++ {
    26  		if rs[i] != other[i] {
    27  			return false
    28  		}
    29  	}
    30  	return true
    31  }
    32  
    33  func (rs HashSlice) HashSet() HashSet {
    34  	hs := make(HashSet, len(rs))
    35  	for _, h := range rs {
    36  		hs[h] = struct{}{}
    37  	}
    38  
    39  	return hs
    40  }