/*

Del - Receives existing data structure, path to delete.

Returns:
`data` - return modified data

*/
970739
func Delete(data []byte, keys ...string) []byte {
	lk := len(keys)
	if lk == 0 {
		return data[:0]
	}

	array := false
	if len(keys[lk-1]) > 0 && string(keys[lk-1][0]) == "[" {
		array = true
	}

	var startOffset, keyOffset int
	endOffset := len(data)
	var err error
	if !array {
		if len(keys) > 1 {
			_, _, startOffset, endOffset, err = internalGet(data, keys[:lk-1]...)
			if err == KeyPathNotFoundError {
				// problem parsing the data
				return data
			}
		}

		keyOffset, err = findKeyStart(data[startOffset:endOffset], keys[lk-1])
		if err == KeyPathNotFoundError {
			// problem parsing the data
			return data
		}
		keyOffset += startOffset
		_, _, _, subEndOffset, _ := internalGet(data[startOffset:endOffset], keys[lk-1])
		endOffset = startOffset + subEndOffset
		tokEnd := tokenEnd(data[endOffset:])
		tokStart := findTokenStart(data[:keyOffset], ","[0])

		if data[endOffset+tokEnd] == ","[0] {
			endOffset += tokEnd + 1
		} else if data[endOffset+tokEnd] == " "[0] && len(data) > endOffset+tokEnd+1 && data[endOffset+tokEnd+1] == ","[0] {
			endOffset += tokEnd + 2
		} else if data[endOffset+tokEnd] == "}"[0] && data[tokStart] == ","[0] {
			keyOffset = tokStart
		}
	} else {
		_, _, keyOffset, endOffset, err = internalGet(data, keys...)
		if err == KeyPathNotFoundError {
			// problem parsing the data
			return data
		}

		tokEnd := tokenEnd(data[endOffset:])
		tokStart := findTokenStart(data[:keyOffset], ","[0])

		if data[endOffset+tokEnd] == ","[0] {
			endOffset += tokEnd + 1
		} else if data[endOffset+tokEnd] == "]"[0] && data[tokStart] == ","[0] {
			keyOffset = tokStart
		}
	}

	// We need to remove remaining trailing comma if we delete las element in the object
	prevTok := lastToken(data[:keyOffset])
	remainedValue := data[endOffset:]

	var newOffset int
	if nextToken(remainedValue) > -1 && remainedValue[nextToken(remainedValue)] == '}' && data[prevTok] == ',' {
		newOffset = prevTok
	} else {
		newOffset = prevTok + 1
	}

	data = append(data[:newOffset], data[endOffset:]...)
	return data
}
294434
func (c *Client) Delete(path string) error {
	pconn, err := c.getIdleConn()
	if err != nil {
		return err
	}

	defer c.returnConn(pconn)

	return pconn.sendCommandExpected(replyFileActionOkay, "DELE %s", path)
}
1373382
func (m *MemoryStorer) Del(key string) error {
	m.mut.Lock()
	delete(m.sessions, key)
	m.mut.Unlock()

	return nil
}
300824
func (c *Client) Del(keys ...string) (int64, error) {
	var ret int64
	args := make([][]byte, len(keys)+1)
	args[0] = []byte("DEL")
	for i, key := range keys {
		args[1+i] = to.Bytes(key)
	}
	err := c.command(&ret, args...)
	return ret, err
}
828717
func (t *Templater) Del(path string) {
	t.m.Lock()
	defer t.m.Unlock()
	delete(t.templates, path)
}
1036845
func Del(id string, params *stripe.RadarValueListParams) (*stripe.RadarValueList, error) {
	return getC().Del(id, params)
}
1012648
func (r *Request) Delete(url string) (*Response, error) {
	return r.Execute(MethodDelete, url)
}
869858
func (kv *KeyValue) Del(key string) error {
	_, err := kv.host.db.Exec(fmt.Sprintf("UPDATE %s SET attr = delete(attr, %s)", pq.QuoteIdentifier(kvPrefix+kv.table), singleQuote(key)))
	return err
}
1204909
func (c *Client) Delete(path string) error {
	return c.Send("DELETE", path, nil, nil)
}
1046541
func (rc *Redis) Del(key string) error {
	var err error
	if _, err = rc.do("DEL", key); err != nil {
		return err
	}
	_, err = rc.do("HDEL", rc.key, key)
	if err != nil {
		if rc.Debug {
			log.Println("[Redis]DelErr: ", err, "Key:", key)
		}
		return err
	}
	if rc.Debug {
		log.Println("[Redis]Del: ", key)
	}
	return err
}
8040
func (t *Trie) Del(path []string) bool {
	if len(path) == 0 {
		return t.delentry()
	}

	key := path[0]
	newpath := path[1:]

	res, ok := t.Children[key]
	if !ok {
		return false
	}

	return res.Del(newpath)
}
220336
func (s Store) Del(key string) {
	s.Lock()
	delete(s.m, key)
	s.Unlock()
}
1299784
func (c *Client) Del(key string) (err error) {
	return c.DelCAS(key, 0)
}
625701
func (r RedisPipeline) Del(keys ...string) *redis.IntCmd {
	return r.pipeline.Del(keys...)
}
1288482
func (d *DataBagService) Delete(name string) (result *DataBag, err error) {
	path := fmt.Sprintf("data/%s", name)
	err = d.client.magicRequestDecoder("DELETE", path, nil, &result)
	return
}
678819
func (f *Flash) Del(key string) {
	if f.Has(key) {
		f.changed = true
	}
	delete(f.v, key)
}
536495
func Delete(url string, v ...interface{}) (*Resp, error) {
	return std.Delete(url, v...)
}