@@ -47,17 +47,15 @@ Result<std::vector<std::shared_ptr<Snapshot>>> SnapshotUtil::AncestorsOf(
4747Result<bool > SnapshotUtil::IsAncestorOf (const Table& table, int64_t snapshot_id,
4848 int64_t ancestor_snapshot_id) {
4949 ICEBERG_ASSIGN_OR_RAISE (auto ancestors, AncestorsOf (table, snapshot_id));
50- for (const auto & snapshot : ancestors) {
51- if (snapshot->snapshot_id == ancestor_snapshot_id) {
52- return true ;
53- }
54- }
55- return false ;
50+ return std::ranges::any_of (ancestors, [ancestor_snapshot_id](const auto & snapshot) {
51+ return snapshot->snapshot_id == ancestor_snapshot_id;
52+ });
5653}
5754
5855Result<bool > SnapshotUtil::IsAncestorOf (const Table& table,
5956 int64_t ancestor_snapshot_id) {
6057 ICEBERG_ASSIGN_OR_RAISE (auto current, table.current_snapshot ());
58+ ICEBERG_DCHECK (current, " Current snapshot is null" );
6159 return IsAncestorOf (table, current->snapshot_id , ancestor_snapshot_id);
6260}
6361
@@ -73,8 +71,14 @@ Result<bool> SnapshotUtil::IsParentAncestorOf(const Table& table, int64_t snapsh
7371
7472Result<std::vector<std::shared_ptr<Snapshot>>> SnapshotUtil::CurrentAncestors (
7573 const Table& table) {
76- ICEBERG_ASSIGN_OR_RAISE (auto current, table.current_snapshot ());
77- return AncestorsOf (table, current);
74+ auto current_result = table.current_snapshot ();
75+ if (!current_result.has_value ()) {
76+ if (current_result.error ().kind == ErrorKind::kNotFound ) {
77+ return std::vector<std::shared_ptr<Snapshot>>();
78+ }
79+ return std::unexpected<Error>(current_result.error ());
80+ }
81+ return AncestorsOf (table, current_result.value ());
7882}
7983
8084Result<std::vector<int64_t >> SnapshotUtil::CurrentAncestorIds (const Table& table) {
@@ -105,10 +109,7 @@ Result<std::optional<std::shared_ptr<Snapshot>>> SnapshotUtil::OldestAncestorAft
105109 auto current_result = table.current_snapshot ();
106110 ICEBERG_RETURN_NULLOPT_IF_NOT_FOUND (current_result);
107111 auto current = current_result.value ();
108- if (!current) {
109- // there are no snapshots or ancestors
110- return std::nullopt ;
111- }
112+ ICEBERG_DCHECK (current, " Current snapshot is null" );
112113
113114 std::optional<std::shared_ptr<Snapshot>> last_snapshot = std::nullopt ;
114115 ICEBERG_ASSIGN_OR_RAISE (auto ancestors, AncestorsOf (table, current));
0 commit comments