| 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://developers.google.com/open-source/licenses/bsd |
| 7 | */ |
| 8 | |
| 9 | #ifndef REFTABLE_ITERATOR_H |
| 10 | #define REFTABLE_ITERATOR_H |
| 11 | |
| 12 | #include "reftable-system.h" |
| 13 | #include "reftable-record.h" |
| 14 | |
| 15 | struct reftable_iterator_vtable; |
| 16 | |
| 17 | /* iterator is the generic interface for walking over data stored in a |
| 18 | * reftable. |
| 19 | */ |
| 20 | struct reftable_iterator { |
| 21 | struct reftable_iterator_vtable *ops; |
| 22 | void *iter_arg; |
| 23 | }; |
| 24 | |
| 25 | /* |
| 26 | * Position the iterator at the ref record with given name such that the next |
| 27 | * call to `next_ref()` would yield the record. |
| 28 | */ |
| 29 | int reftable_iterator_seek_ref(struct reftable_iterator *it, |
| 30 | const char *name); |
| 31 | |
| 32 | /* reads the next reftable_ref_record. Returns < 0 for error, 0 for OK and > 0: |
| 33 | * end of iteration. |
| 34 | */ |
| 35 | int reftable_iterator_next_ref(struct reftable_iterator *it, |
| 36 | struct reftable_ref_record *ref); |
| 37 | |
| 38 | /* |
| 39 | * Position the iterator at the log record with given name and update index |
| 40 | * such that the next call to `next_log()` would yield the record. |
| 41 | */ |
| 42 | int reftable_iterator_seek_log_at(struct reftable_iterator *it, |
| 43 | const char *name, uint64_t update_index); |
| 44 | |
| 45 | /* |
| 46 | * Position the iterator at the newest log record with given name such that the |
| 47 | * next call to `next_log()` would yield the record. |
| 48 | */ |
| 49 | int reftable_iterator_seek_log(struct reftable_iterator *it, |
| 50 | const char *name); |
| 51 | |
| 52 | /* reads the next reftable_log_record. Returns < 0 for error, 0 for OK and > 0: |
| 53 | * end of iteration. |
| 54 | */ |
| 55 | int reftable_iterator_next_log(struct reftable_iterator *it, |
| 56 | struct reftable_log_record *log); |
| 57 | |
| 58 | /* releases resources associated with an iterator. */ |
| 59 | void reftable_iterator_destroy(struct reftable_iterator *it); |
| 60 | |
| 61 | #endif |