mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
5bf96e0c39
Reftable iterators are created by seeking on the parent structure of a corresponding record. For example, to create an iterator for the merged table you would call `reftable_merged_table_seek_ref()`. Most notably, it is not posible to create an iterator and then seek it afterwards. While this may be a bit easier to reason about, it comes with two significant downsides. The first downside is that the logic to find records is split up between the parent data structure and the iterator itself. Conceptually, it is more straight forward if all that logic was contained in a single place, which should be the iterator. The second and more significant downside is that it is impossible to reuse iterators for multiple seeks. Whenever you want to look up a record, you need to re-create the whole infrastructure again, which is quite a waste of time. Furthermore, it is impossible to optimize seeks, such as when seeking the same record multiple times. To address this, we essentially split up the concerns properly such that the parent data structure is responsible for setting up the iterator via a new `init_iter()` callback, whereas the iterator handles seeks via a new `seek()` callback. This will eventually allow us to call `seek()` on the iterator multiple times, where every iterator can potentially optimize for certain cases. Note that at this point in time we are not yet ready to reuse the iterators. This will be left for a future patch series. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
38 lines
1.0 KiB
C
38 lines
1.0 KiB
C
/*
|
|
Copyright 2020 Google LLC
|
|
|
|
Use of this source code is governed by a BSD-style
|
|
license that can be found in the LICENSE file or at
|
|
https://developers.google.com/open-source/licenses/bsd
|
|
*/
|
|
|
|
#ifndef GENERIC_H
|
|
#define GENERIC_H
|
|
|
|
#include "record.h"
|
|
#include "reftable-generic.h"
|
|
|
|
/* generic interface to reftables */
|
|
struct reftable_table_vtable {
|
|
void (*init_iter)(void *tab, struct reftable_iterator *it, uint8_t typ);
|
|
uint32_t (*hash_id)(void *tab);
|
|
uint64_t (*min_update_index)(void *tab);
|
|
uint64_t (*max_update_index)(void *tab);
|
|
};
|
|
|
|
void table_init_iter(struct reftable_table *tab,
|
|
struct reftable_iterator *it,
|
|
uint8_t typ);
|
|
|
|
struct reftable_iterator_vtable {
|
|
int (*seek)(void *iter_arg, struct reftable_record *want);
|
|
int (*next)(void *iter_arg, struct reftable_record *rec);
|
|
void (*close)(void *iter_arg);
|
|
};
|
|
|
|
void iterator_set_empty(struct reftable_iterator *it);
|
|
int iterator_seek(struct reftable_iterator *it, struct reftable_record *want);
|
|
int iterator_next(struct reftable_iterator *it, struct reftable_record *rec);
|
|
|
|
#endif
|