// SetWithHint assigns a value to a key.
// The hash/seed params must be previous generated from the Hash function
// sharing the same key. Doing otherwise will risk corruption to map.
// Returns the previous value, or false when no value was assigned.
SetWithHint assigns a value to a key.
The hash/seed params must be previous generated from the Hash function
sharing the same key. Doing otherwise will risk corruption to map.
Returns the previous value, or false when no value was assigned.
// SetWithHint assigns a value to a key . // The hash / seed params must be previous generated from the Hash function // sharing the same key . Doing otherwise will risk corruption to map . // Returns the previous value or false when no value was assigned .
func (m *Map) SetWithHint(key string, hash, seed uint32, value interface{}) (interface{}, bool) {
	if len(m.entries) == 0 {
		if m.stable == 0 {
			atomic.StoreUint32(&m.seed, makeSeed())
		} else {
			atomic.StoreUint32(&m.seed, m.stable)
		}
		m.entries = make([]entry, 1)
	}
	if atomic.LoadUint32(&m.seed) != seed {
		return m.Set(key, value)
	}
	var probe int
	if m.len > len(m.entries)/2 {
		probe = 1
	}
	var dist uint32 = 1
	i := int(hash) & m.mask
	for j := 0; ; j++ {
		if m.entries[i].dist == 0 {
			m.entries[i].dist = dist
			m.entries[i].hash = hash
			m.entries[i].key = key
			m.entries[i].value = value
			m.len++
			return nil, false
		}
		if hash == m.entries[i].hash && key == m.entries[i].key {
			old := m.entries[i].value
			m.entries[i].value = value
			return old, true
		}
		if m.entries[i].dist < dist {
			m.entries[i].hash, hash = hash, m.entries[i].hash
			m.entries[i].key, key = key, m.entries[i].key
			m.entries[i].value, value = value, m.entries[i].value
			m.entries[i].dist, dist = dist, m.entries[i].dist
		}
		i = (i + 1) & m.mask
		dist++
		if probe > 0 {
			if probe == 16 {
				m.grow()
				return m.Set(key, value)
			}
			probe++
		}
	}
}
func ( m * Map ) SetWithHint ( key string , hash , seed uint32 , value interface { } ) ( interface { } , bool ) { if len ( m . entries ) == 0 { if m . stable == 0 { atomic . StoreUint32 ( & m . seed , makeSeed ( ) ) } else { atomic . StoreUint32 ( & m . seed , m . stable ) } m . entries = make ( [ ] entry , 1 ) } if atomic . LoadUint32 ( & m . seed ) != seed { return m . Set ( key , value ) } var probe int if m . len > len ( m . entries ) / 2 { probe = 1 } var dist uint32 = 1 i := int ( hash ) & m . mask for j := 0 ; ; j ++ { if m . entries [ i ] . dist == 0 { m . entries [ i ] . dist = dist m . entries [ i ] . hash = hash m . entries [ i ] . key = key m . entries [ i ] . value = value m . len ++ return nil , false } if hash == m . entries [ i ] . hash && key == m . entries [ i ] . key { old := m . entries [ i ] . value m . entries [ i ] . value = value return old , true } if m . entries [ i ] . dist < dist { m . entries [ i ] . hash , hash = hash , m . entries [ i ] . hash m . entries [ i ] . key , key = key , m . entries [ i ] . key m . entries [ i ] . value , value = value , m . entries [ i ] . value m . entries [ i ] . dist , dist = dist , m . entries [ i ] . dist } i = ( i + 1 ) & m . mask dist ++ if probe > 0 { if probe == 16 { m . grow ( ) return m . Set ( key , value ) } probe ++ } } }
SetWithHint assigns a value to a key.
SetWithHint assigns a value to a key .