MCPcopy Create free account
hub / github.com/beeker1121/goque / Update

Method Update

stack.go:191–218  ·  view source on GitHub ↗

Update updates an item in the stack without changing its position.

(id uint64, newValue []byte)

Source from the content-addressed store, hash-verified

189
190// Update updates an item in the stack without changing its position.
191func (s *Stack) Update(id uint64, newValue []byte) (*Item, error) {
192 s.Lock()
193 defer s.Unlock()
194
195 // Check if stack is closed.
196 if !s.isOpen {
197 return nil, ErrDBClosed
198 }
199
200 // Check if item exists in stack.
201 if id > s.head || id <= s.tail {
202 return nil, ErrOutOfBounds
203 }
204
205 // Create new Item.
206 item := &Item{
207 ID: id,
208 Key: idToKey(id),
209 Value: newValue,
210 }
211
212 // Update this item in the stack.
213 if err := s.db.Put(item.Key, item.Value, nil); err != nil {
214 return nil, err
215 }
216
217 return item, nil
218}
219
220// UpdateString is a helper function for Update that accepts a value
221// as a string rather than a byte slice.

Callers 14

UpdateStringMethod · 0.95
UpdateObjectMethod · 0.95
UpdateObjectAsJSONMethod · 0.95
TestStackUpdateFunction · 0.45
Example_prefixQueueFunction · 0.45
TestQueueUpdateFunction · 0.45
Example_queueFunction · 0.45
Example_priorityQueueFunction · 0.45
TestPriorityQueueUpdateFunction · 0.45

Calls 1

idToKeyFunction · 0.85

Tested by 11

TestStackUpdateFunction · 0.36
Example_prefixQueueFunction · 0.36
TestQueueUpdateFunction · 0.36
Example_queueFunction · 0.36
Example_priorityQueueFunction · 0.36
TestPriorityQueueUpdateFunction · 0.36
Example_stackFunction · 0.36