MCPcopy
hub / github.com/kopia/kopia / newInternalMapWithOptions

Function newInternalMapWithOptions

internal/bigmap/bigmap_internal.go:410–454  ·  view source on GitHub ↗

newInternalMapWithOptions creates a new instance of internalMap.

(ctx context.Context, hasValues bool, opts *Options)

Source from the content-addressed store, hash-verified

408
409// newInternalMapWithOptions creates a new instance of internalMap.
410func newInternalMapWithOptions(ctx context.Context, hasValues bool, opts *Options) (*internalMap, error) {
411 if opts == nil {
412 opts = &Options{}
413 }
414
415 if opts.LoadFactorPercentage == 0 {
416 opts.LoadFactorPercentage = defaultLoadFactorPercentage
417 }
418
419 if opts.MemorySegmentSize == 0 {
420 opts.MemorySegmentSize = defaultMemorySegmentSize
421 }
422
423 if opts.NumMemorySegments == 0 {
424 opts.NumMemorySegments = defaultNumMemorySegments
425 }
426
427 if opts.FileSegmentSize == 0 {
428 opts.FileSegmentSize = defaultFileSegmentSize
429 }
430
431 if opts.InitialSizeLogarithm == 0 {
432 opts.InitialSizeLogarithm = defaultInitialSizeLogarithm
433 }
434
435 tablewSizeIndex := opts.InitialSizeLogarithm - minSizeLogarithm
436
437 if tablewSizeIndex < 1 {
438 return nil, errors.New("invalid initial size")
439 }
440
441 m := &internalMap{
442 hasValues: hasValues,
443 opts: *opts,
444 tableSizeIndex: tablewSizeIndex,
445 h2Prime: tableSizesPrimes[tablewSizeIndex-1], // h2 prime < number of slots
446 slots: make([]entry, tableSizesPrimes[tablewSizeIndex]),
447 }
448
449 m.mu.Lock()
450 m.segments = append(m.segments, m.newSegment(ctx))
451 m.mu.Unlock()
452
453 return m, nil
454}

Callers 7

TestGrowingMapFunction · 0.85
TestErrorsFunction · 0.85
TestMapWithoutValueFunction · 0.85
NewSetWithOptionsFunction · 0.85
NewMapWithOptionsFunction · 0.85
newInternalMapFunction · 0.85

Calls 3

newSegmentMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65

Tested by 4

TestGrowingMapFunction · 0.68
TestErrorsFunction · 0.68
TestMapWithoutValueFunction · 0.68