init initializes the stack data.
()
| 313 | |
| 314 | // init initializes the stack data. |
| 315 | func (s *Stack) init() error { |
| 316 | // Create a new LevelDB Iterator. |
| 317 | iter := s.db.NewIterator(nil, nil) |
| 318 | defer iter.Release() |
| 319 | |
| 320 | // Set stack head to the last item. |
| 321 | if iter.Last() { |
| 322 | s.head = keyToID(iter.Key()) |
| 323 | } |
| 324 | |
| 325 | // Set stack tail to the first item. |
| 326 | if iter.First() { |
| 327 | s.tail = keyToID(iter.Key()) - 1 |
| 328 | } |
| 329 | |
| 330 | return iter.Error() |
| 331 | } |