]> git.ipfire.org Git - thirdparty/git.git/blob - reftable/iter.h
The 20th batch
[thirdparty/git.git] / reftable / iter.h
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 ITER_H
10 #define ITER_H
11
12 #include "system.h"
13 #include "block.h"
14 #include "record.h"
15
16 #include "reftable-iterator.h"
17
18 /*
19 * The virtual function table for implementing generic reftable iterators.
20 */
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);
25 };
26
27 /*
28 * Position the iterator at the wanted record such that a call to
29 * `iterator_next()` would return that record, if it exists.
30 */
31 int iterator_seek(struct reftable_iterator *it, struct reftable_record *want);
32
33 /*
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.
36 */
37 int iterator_next(struct reftable_iterator *it, struct reftable_record *rec);
38
39 /*
40 * Set up the iterator such that it behaves the same as an iterator with no
41 * entries.
42 */
43 void iterator_set_empty(struct reftable_iterator *it);
44
45 /* iterator that produces only ref records that point to `oid` */
46 struct filtering_ref_iterator {
47 struct strbuf oid;
48 struct reftable_iterator it;
49 };
50 #define FILTERING_REF_ITERATOR_INIT \
51 { \
52 .oid = STRBUF_INIT \
53 }
54
55 void iterator_from_filtering_ref_iterator(struct reftable_iterator *,
56 struct filtering_ref_iterator *);
57
58 /* iterator that produces only ref records that point to `oid`,
59 * but using the object index.
60 */
61 struct indexed_table_ref_iter {
62 struct reftable_reader *r;
63 struct strbuf oid;
64
65 /* mutable */
66 uint64_t *offsets;
67
68 /* Points to the next offset to read. */
69 int offset_idx;
70 int offset_len;
71 struct block_reader block_reader;
72 struct block_iter cur;
73 int is_finished;
74 };
75
76 #define INDEXED_TABLE_REF_ITER_INIT { \
77 .cur = BLOCK_ITER_INIT, \
78 .oid = STRBUF_INIT, \
79 }
80
81 void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
82 struct indexed_table_ref_iter *itr);
83
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);
88
89 #endif