newInternalMapWithOptions creates a new instance of internalMap.
(ctx context.Context, hasValues bool, opts *Options)
| 408 | |
| 409 | // newInternalMapWithOptions creates a new instance of internalMap. |
| 410 | func 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 | } |