MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / LPop

Method LPop

structure/list.go:173–190  ·  view source on GitHub ↗

LPop returns and removes the leftmost value of a list associated with a key. If the key does not exist, an error is returned. If the list is empty, an error is returned.

(key string)

Source from the content-addressed store, hash-verified

171// If the key does not exist, an error is returned.
172// If the list is empty, an error is returned.
173func (l *ListStructure) LPop(key string) (interface{}, error) {
174 // Get the list
175 lst, _, err := l.getListFromDB(key, false)
176 if err != nil {
177 return nil, err
178 }
179 // Return error if the list is empty
180 if lst.Length == 0 {
181 return nil, ErrListEmpty
182 }
183
184 popValue := lst.Head.Value
185 lst.Head = lst.Head.Next
186 lst.Length--
187
188 // Store in the database
189 return popValue, l.setListToDB(key, lst, 0)
190}
191
192// RPop returns and removes the rightmost value of a list associated with a key.
193// If the key does not exist, an error is returned.

Callers

nothing calls this directly

Calls 2

getListFromDBMethod · 0.95
setListToDBMethod · 0.95

Tested by

no test coverage detected