// Put adds or overwrites an item in(to) the shards internal byte-array.
Put adds or overwrites an item in(to) the shards internal byte-array.
// Put adds or overwrites an item in ( to ) the shards internal byte - array .
func (S *Shard) Put(key uint64, val []byte) error {
	dataLength := uint64(len(val))
	if dataLength > S.entrysize {
		_lval := dataLength
		maxSize := S.entrysize
		return fmt.Errorf("shard put: value size to long (%d > %d)", _lval, maxSize)
	}
	S.hitExpirationService(key, ExpirationService.BeforeLock)
	defer func() {
		S.hitExpirationService(key, ExpirationService.Access)
		S.Unlock()
		S.hitExpirationService(key, ExpirationService.AfterAccess)
	}()
	S.Lock()
	S.hitExpirationService(key, ExpirationService.Lock)
	ptr, ok := S.ptrs.Get(key)
	if !ok {
		ptr, ok = S.freePtrs.Dequeue()
		if !ok {
			ptr = S.size
			S.sizeCheck(S.entrysize + LengthBytes)
		}
		S.ptrs.Put(key, ptr)
	}
	dataIndex := ptr + LengthBytes
	binary.LittleEndian.PutUint64(S.array[ptr:dataIndex], dataLength)
	copy(S.array[dataIndex:dataIndex+dataLength], val)
	S.size += LengthBytes
	S.size += S.entrysize
	return nil
}
func ( S * Shard ) Put ( key uint64 , val [ ] byte ) error { dataLength := uint64 ( len ( val ) ) if dataLength > S . entrysize { _lval := dataLength maxSize := S . entrysize return fmt . Errorf ( " " , _lval , maxSize ) } S . hitExpirationService ( key , ExpirationService . BeforeLock ) defer func ( ) { S . hitExpirationService ( key , ExpirationService . Access ) S . Unlock ( ) S . hitExpirationService ( key , ExpirationService . AfterAccess ) } ( ) S . Lock ( ) S . hitExpirationService ( key , ExpirationService . Lock ) ptr , ok := S . ptrs . Get ( key ) if ! ok { ptr , ok = S . freePtrs . Dequeue ( ) if ! ok { ptr = S . size S . sizeCheck ( S . entrysize + LengthBytes ) } S . ptrs . Put ( key , ptr ) } dataIndex := ptr + LengthBytes binary . LittleEndian . PutUint64 ( S . array [ ptr : dataIndex ] , dataLength ) copy ( S . array [ dataIndex : dataIndex + dataLength ] , val ) S . size += LengthBytes S . size += S . entrysize return nil }
Put adds or overwrites an item in(to) the shards internal byte-array.
Put adds or overwrites an item in ( to ) the shards internal byte - array .