Lagrange
AdjacencyList.h
1/*
2 * Copyright 2022 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <vector>
15
16#include <lagrange/utils/assert.h>
17#include <lagrange/utils/span.h>
18
19namespace lagrange {
20
25
31template <typename Index>
33{
34public:
35 using ValueArray = std::vector<Index>;
36 using IndexArray = std::vector<size_t>;
37
38public:
49 AdjacencyList(ValueArray data, IndexArray indices)
50 : m_data(std::move(data))
51 , m_indices(std::move(indices))
52 {}
53
59 [[nodiscard]] size_t get_num_entries() const { return m_indices.size() - 1; }
60
68 [[nodiscard]] span<const Index> get_neighbors(size_t i) const
69 {
71 i + 1 < m_indices.size(),
72 "Invalid index, perhaps adjacency list is uninitialized?");
73 return {m_data.data() + m_indices[i], m_indices[i + 1] - m_indices[i]};
74 }
75
83 [[nodiscard]] size_t get_num_neighbors(size_t i) const
84 {
86 i + 1 < m_indices.size(),
87 "Invalid index, perhaps adjacency list is uninitialized?");
88 return m_indices[i + 1] - m_indices[i];
89 }
90
91private:
92 ValueArray m_data;
93 IndexArray m_indices;
94};
95
97
98} // namespace lagrange
Adjacency list.
Definition: AdjacencyList.h:33
span< const Index > get_neighbors(size_t i) const
Get adjacency list of entry i.
Definition: AdjacencyList.h:68
AdjacencyList(ValueArray data, IndexArray indices)
Initialize adjacency list data.
Definition: AdjacencyList.h:49
size_t get_num_entries() const
Get total number of entries.
Definition: AdjacencyList.h:59
size_t get_num_neighbors(size_t i) const
Get the number of neighbors of a given entry.
Definition: AdjacencyList.h:83
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition: span.h:27
Main namespace for Lagrange.
Definition: AABBIGL.h:30