2 Copyright 2020 Google LLC
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
16 #include "reftable-iterator.h"
19 * The virtual function table for implementing generic reftable iterators.
21 struct reftable_iterator_vtable
{
22 int (*seek
)(void *iter_arg
, struct reftable_record
*want
);
23 int (*next
)(void *iter_arg
, struct reftable_record
*rec
);
24 void (*close
)(void *iter_arg
);
28 * Position the iterator at the wanted record such that a call to
29 * `iterator_next()` would return that record, if it exists.
31 int iterator_seek(struct reftable_iterator
*it
, struct reftable_record
*want
);
34 * Yield the next record and advance the iterator. Returns <0 on error, 0 when
35 * a record was yielded, and >0 when the iterator hit an error.
37 int iterator_next(struct reftable_iterator
*it
, struct reftable_record
*rec
);
40 * Set up the iterator such that it behaves the same as an iterator with no
43 void iterator_set_empty(struct reftable_iterator
*it
);
45 /* iterator that produces only ref records that point to `oid` */
46 struct filtering_ref_iterator
{
48 struct reftable_iterator it
;
50 #define FILTERING_REF_ITERATOR_INIT \
55 void iterator_from_filtering_ref_iterator(struct reftable_iterator
*,
56 struct filtering_ref_iterator
*);
58 /* iterator that produces only ref records that point to `oid`,
59 * but using the object index.
61 struct indexed_table_ref_iter
{
62 struct reftable_reader
*r
;
68 /* Points to the next offset to read. */
71 struct block_reader block_reader
;
72 struct block_iter cur
;
76 #define INDEXED_TABLE_REF_ITER_INIT { \
77 .cur = BLOCK_ITER_INIT, \
81 void iterator_from_indexed_table_ref_iter(struct reftable_iterator
*it
,
82 struct indexed_table_ref_iter
*itr
);
84 /* Takes ownership of `offsets` */
85 int new_indexed_table_ref_iter(struct indexed_table_ref_iter
**dest
,
86 struct reftable_reader
*r
, uint8_t *oid
,
87 int oid_len
, uint64_t *offsets
, int offset_len
);