MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / SDiffByOneBucket

Method SDiffByOneBucket

tx_set.go:253–279  ·  view source on GitHub ↗

SDiffByOneBucket returns the members of the set resulting from the difference between the first set and all the successive sets in one bucket.

(bucket string, key1, key2 []byte)

Source from the content-addressed store, hash-verified

251// SDiffByOneBucket returns the members of the set resulting from the difference
252// between the first set and all the successive sets in one bucket.
253func (tx *Tx) SDiffByOneBucket(bucket string, key1, key2 []byte) ([][]byte, error) {
254 if err := tx.checkTxIsClosed(); err != nil {
255 return nil, err
256 }
257 b, err := tx.db.bucketMgr.GetBucket(DataStructureSet, bucket)
258 if err != nil {
259 return nil, err
260 }
261 bucketId := b.Id
262 if set, ok := tx.db.Index.Set.exist(bucketId); ok {
263 items, err := set.SDiff(string(key1), string(key2))
264 if err != nil {
265 return nil, err
266 }
267 values := make([][]byte, len(items))
268 for i, item := range items {
269 value, err := tx.db.getValueByRecord(item)
270 if err != nil {
271 return nil, err
272 }
273 values[i] = value
274 }
275 return values, nil
276 }
277
278 return nil, ErrBucketNotFound
279}
280
281// SDiffByTwoBuckets returns the members of the set resulting from the difference
282// between the first set and all the successive sets in two buckets.

Callers 2

txSDiffByOneBucketFunction · 0.80
testSDiffByOneBucketFunction · 0.80

Calls 5

checkTxIsClosedMethod · 0.95
GetBucketMethod · 0.80
existMethod · 0.80
SDiffMethod · 0.80
getValueByRecordMethod · 0.80

Tested by 1

txSDiffByOneBucketFunction · 0.64