// Initialize the LRU cache instance. O(capacity)
772409
func (b *LRUCache) Init(capacity uint) {
	b.table = make(map[string]*entry, capacity)
	b.priorityQueue = make([]*entry, 0, capacity)
	b.lruList.Init()
	b.freeList.Init()
	heap.Init(&b.priorityQueue)

	// Reserve all the entries in one giant continous block of memory
	arrayOfEntries := make([]entry, capacity)
	for i := uint(0); i < capacity; i++ {
		e := &arrayOfEntries[i]
		e.element.Value = e
		e.index = -1
		b.freeList.PushElementBack(&e.element)
	}
}
780454
func NewLRU(capacity int) Cacher {
	r := &lru{capacity: capacity}
	r.reset()
	return r
}
530651
func newCache(size int) *cache {
	mc := &cache{
		size:     size,
		inQueue:  make(map[string]*MessageRow),
		inFlight: make(map[string]bool),
	}
	return mc
}
829711
func (u *uploader) init() {
	if u.cfg.Concurrency == 0 {
		u.cfg.Concurrency = DefaultUploadConcurrency
	}
	if u.cfg.PartSize == 0 {
		u.cfg.PartSize = DefaultUploadPartSize
	}
	if u.cfg.MaxUploadParts == 0 {
		u.cfg.MaxUploadParts = MaxUploadParts
	}

	u.bufferPool = sync.Pool{
		New: func() interface{} { return make([]byte, u.cfg.PartSize) },
	}

	// Try to get the total size for some optimizations
	u.initSize()
}
911610
func NewSimpleLRUCache(capacity uint, guard float64, quota uint64) *SimpleLRUCache {
	if capacity <= 0 {
		panic("capacity of LRU Cache should be positive.")
	}
	return &SimpleLRUCache{
		capacity: capacity,
		size:     0,
		quota:    quota,
		guard:    guard,
		elements: make(map[string]*list.Element),
		cache:    list.New(),
	}
}
854440
func init() {
	var (
		workloads, traceMode, compressorMode, readLatency, channelzOn string
		preloaderMode                                                 string
		readKbps, readMtu, readMaxConcurrentCalls                     intSliceType
		readReqSizeBytes, readRespSizeBytes                           intSliceType
	)
	flag.StringVar(&workloads, "workloads", workloadsAll,
		fmt.Sprintf("Workloads to execute - One of: %v", strings.Join(allWorkloads, ", ")))
	flag.StringVar(&traceMode, "trace", modeOff,
		fmt.Sprintf("Trace mode - One of: %v", strings.Join(allTraceModes, ", ")))
	flag.StringVar(&readLatency, "latency", "", "Simulated one-way network latency - may be a comma-separated list")
	flag.StringVar(&channelzOn, "channelz", modeOff, "whether channelz should be turned on")
	flag.DurationVar(&benchtime, "benchtime", time.Second, "Configures the amount of time to run each benchmark")
	flag.Var(&readKbps, "kbps", "Simulated network throughput (in kbps) - may be a comma-separated list")
	flag.Var(&readMtu, "mtu", "Simulated network MTU (Maximum Transmission Unit) - may be a comma-separated list")
	flag.Var(&readMaxConcurrentCalls, "maxConcurrentCalls", "Number of concurrent RPCs during benchmarks")
	flag.Var(&readReqSizeBytes, "reqSizeBytes", "Request size in bytes - may be a comma-separated list")
	flag.Var(&readRespSizeBytes, "respSizeBytes", "Response size in bytes - may be a comma-separated list")
	flag.StringVar(&memProfile, "memProfile", "", "Enables memory profiling output to the filename provided.")
	flag.IntVar(&memProfileRate, "memProfileRate", 512*1024, "Configures the memory profiling rate. \n"+
		"memProfile should be set before setting profile rate. To include every allocated block in the profile, "+
		"set MemProfileRate to 1. To turn off profiling entirely, set MemProfileRate to 0. 512 * 1024 by default.")
	flag.StringVar(&cpuProfile, "cpuProfile", "", "Enables CPU profiling output to the filename provided")
	flag.StringVar(&compressorMode, "compression", modeOff,
		fmt.Sprintf("Compression mode - One of: %v", strings.Join(allCompressionModes, ", ")))
	flag.StringVar(&preloaderMode, "preloader", modeOff,
		fmt.Sprintf("Preloader mode - One of: %v", strings.Join(allPreloaderModes, ", ")))
	flag.StringVar(&benchmarkResultFile, "resultFile", "", "Save the benchmark result into a binary file")
	flag.StringVar(&networkMode, "networkMode", "", "Network mode includes LAN, WAN, Local and Longhaul")
	flag.Parse()
	if flag.NArg() != 0 {
		log.Fatal("Error: unparsed arguments: ", flag.Args())
	}
	switch workloads {
	case workloadsUnary:
		runMode[0] = true
		runMode[1] = false
		runMode[2] = false
	case workloadsStreaming:
		runMode[0] = false
		runMode[1] = true
		runMode[2] = false
	case workloadsUnconstrained:
		runMode[0] = false
		runMode[1] = false
		runMode[2] = true
	case workloadsAll:
		runMode[0] = true
		runMode[1] = true
		runMode[2] = true
	default:
		log.Fatalf("Unknown workloads setting: %v (want one of: %v)",
			workloads, strings.Join(allWorkloads, ", "))
	}
	modeCompressor = setModeCompressor(compressorMode)
	enablePreloader = setMode(preloaderMode)
	enableTrace = setMode(traceMode)
	enableChannelz = setMode(channelzOn)
	// Time input formats as (time + unit).
	readTimeFromInput(&ltc, readLatency)
	readIntFromIntSlice(&kbps, readKbps)
	readIntFromIntSlice(&mtu, readMtu)
	readIntFromIntSlice(&maxConcurrentCalls, readMaxConcurrentCalls)
	readIntFromIntSlice(&reqSizeBytes, readReqSizeBytes)
	readIntFromIntSlice(&respSizeBytes, readRespSizeBytes)
	// Re-write latency, kpbs and mtu if network mode is set.
	if network, ok := networks[networkMode]; ok {
		ltc = []time.Duration{network.Latency}
		kbps = []int{network.Kbps}
		mtu = []int{network.MTU}
	}
}
440997
func (h LRUHandle) LRU(c context.Context) *lru.Cache {
	return c.Value(&processCacheKey).(*ProcessCacheData).caches[int(h)]
}
1328265
func NewLRUCacher(store core.CacheStore, maxElementSize int) *LRUCacher {
	return NewLRUCacher2(store, 3600*time.Second, maxElementSize)
}
1224304
func NewCache(size int64) *Storage {
	return &Storage{
		maxSize: size,
		lru:     lru.New(0), // infinite items; we evict by size, not count
	}
}
403369
func NewLRUClientSessionCache(capacity int) ClientSessionCache {
	const defaultSessionCacheCapacity = 64

	if capacity < 1 {
		capacity = defaultSessionCacheCapacity
	}
	return &lruSessionCache{
		m:        make(map[string]*list.Element),
		q:        list.New(),
		capacity: capacity,
	}
}
565288
func NewLRUCache(capacity int) *Cache {
	return NewNativeCache(C.rocksdb_cache_create_lru(C.size_t(capacity)))
}
871628
func (conn *UnixConn) initialize() (*UnixConn, error) {
	if err := conn.unixConn.SetWriteBuffer(bufSize); err != nil {
		return nil, errors.Wrap(err, "setting write buffer size")
	}
	return conn, nil
}
608563
func (c *Ctx) Initialize() error {
	e := C.Initialize(c.ctx)
	return toError(e)
}
882128
func NewLRUExpireCacheWithClock(maxSize int, clock Clock) *LRUExpireCache {
	cache, err := lru.New(maxSize)
	if err != nil {
		// if called with an invalid size
		panic(err)
	}
	return &LRUExpireCache{clock: clock, cache: cache}
}
631589
func (l *Loader) init() {
	if l.loading == nil {
		l.loading = stringset.New(1)
		l.sources = make(map[string]string, 1)
		l.symbols = make(map[string]*Struct, 1)
	}
}
907291
func Init(h sort.Interface) {
	// heapify
	n := h.Len()
	for i := n/2 - 1; i >= 0; i-- {
		heapDown(n, h.Less, h.Swap, i)
	}
}
1190494
func Init(dbFile string, cacheSize int) error {
	if cacheSize <= 0 {
		cacheSize = DefaultCacheSize
		log.Debugf("Defaulted ip cache size to %v", cacheSize)
	}
	_db, dbDate, err := readDbFromFile(dbFile)
	if err != nil {
		_db, dbDate, err = readDbFromWeb(dbFile)
		if err != nil {
			return fmt.Errorf("Unable to read DB from file or web: %v", err)
		}
	}
	dbMutex.Lock()
	cityCache, _ = lru.New(cacheSize)
	regionCache, _ = lru.New(cacheSize)
	regionCityCache, _ = lru.New(cacheSize)
	countryCodeCache, _ = lru.New(cacheSize)
	db = _db
	dbMutex.Unlock()
	go keepDbCurrent(dbFile, dbDate)
	return nil
}