Esempio n. 1
0
// Delete removes an item from the list. If the item is the last item in the list,
// the length will decrease.
func (l List) Delete(i int) error {
	if i < 0 {
		return ErrInvalidIndex
	}
	length, err := strconv.Atoi(string(l.b.Get(lengthKey)))
	if err != nil {
		return err
	}
	if i >= length {
		return ErrInvalidIndex
	}

	if i == length-1 {
		newLength := strconv.Itoa(i)
		if err := helpers.PutWrap(l.b, lengthKey, []byte(newLength)); err != nil {
			return err
		}
	}
	if err := helpers.DeleteWrap(l.b, []byte(strconv.Itoa(i))); err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
// Delete deletes from the map.
func (m Map) Delete(key string) error {
	return helpers.DeleteWrap(m.b, []byte(key))
}