polar-objc 5.44
An Objective-C runtime library
Loading...
Searching...
No Matches
polar-sparse-array.h
1/* Internal API: sparse array type for polar-objc.
2 Copyright (C) 2022-2025 Michael Malicoat <[email protected]>
3
4 This file is part of polar-objc.
5
6 polar-objc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
8
9 polar-objc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 details.
12
13 You should have received a copy of the GNU General Public License along with this program; see the file LICENSE. If
14 not, see <http://www.gnu.org/licenses/>.
15*/
16
17#ifndef POLAR_SPARSE_ARRAY_H
18#define POLAR_SPARSE_ARRAY_H
19// polar_sparse_array **************************************************************************************************
20
23
25{
26 polar_btree data_inherited;
27 void *value_element_empty;
28 intptr_t idx_logical_max;
29 polar_sparse_array_page page_empty;
30};
31
33{
34 polar_btree_class data_inherited;
35};
36
37#define POLAR_TYPE_SPARSE_ARRAY ( polar_sparse_array_get_type() )
38
39#define POLAR_SPARSE_ARRAY(inst) ( POLAR_INTERNAL_TYPE_CHECK_INSTANCE_CAST((inst), POLAR_TYPE_SPARSE_ARRAY, polar_sparse_array) )
40#define POLAR_IS_SPARSE_ARRAY(inst) ( POLAR_INTERNAL_TYPE_CHECK_INSTANCE_TYPE((inst), POLAR_TYPE_SPARSE_ARRAY) )
41#define POLAR_SPARSE_ARRAY_CLASS(klass) ( POLAR_INTERNAL_TYPE_CHECK_CLASS_CAST((klass), POLAR_TYPE_SPARSE_ARRAY, polar_sparse_array_class) )
42#define POLAR_IS_SPARSE_ARRAY_CLASS(klass) ( POLAR_INTERNAL_TYPE_CHECK_CLASS_TYPE((klass), POLAR_TYPE_SPARSE_ARRAY) )
43#define POLAR_SPARSE_ARRAY_GET_CLASS(inst) ( POLAR_INTERNAL_TYPE_INSTANCE_GET_CLASS((inst), POLAR_TYPE_SPARSE_ARRAY, polar_sparse_array_class) )
44
45POLAR_FUNCTION_INTERNAL OBJC_FUNCTION_CONSTANT polar_internal_type
46polar_sparse_array_get_type( void );
47
48POLAR_FUNCTION_INTERNAL OBJC_RETURNS_VALID_POINTER polar_sparse_array *
49polar_sparse_array_new( void *value_element_empty );
50
51POLAR_FUNCTION_INTERNAL OBJC_FUNCTION_HOTSPOT void *
52polar_sparse_array_get_element( polar_sparse_array *self, intptr_t idx_logical );
53
54POLAR_FUNCTION_INTERNAL void
55polar_sparse_array_set_element( polar_sparse_array **p_array_target, intptr_t idx_logical, void *value_new );
56
57POLAR_FUNCTION_INTERNAL BOOL
58polar_sparse_array_set_element_if_empty( polar_sparse_array **p_array_target, intptr_t idx_logical, void *value_new );
59
60static inline void *
61polar_sparse_array_swap_element( polar_sparse_array **p_array_target, intptr_t idx_logical, void *value_new )
62{
63 void *result;
64
65 assert( p_array_target != NULL );
66 assert( POLAR_IS_SPARSE_ARRAY(*p_array_target) );
67 assert( idx_logical >= 0 );
68
69 result = polar_sparse_array_get_element(*p_array_target, idx_logical);
70 polar_sparse_array_set_element(p_array_target, idx_logical, value_new);
71
72 return result;
73}
74
75static inline BOOL
76polar_sparse_array_test_element_empty( polar_sparse_array *self, intptr_t idx_logical )
77{
78 assert( POLAR_IS_SPARSE_ARRAY(self) );
79 assert( idx_logical >= 0 );
80
81 return ( polar_sparse_array_get_element(self, idx_logical) == self->value_element_empty );
82}
83
84#endif // POLAR_SPARSE_ARRAY_H
Definition polar-btree.h:33
Definition polar-btree.h:25
Definition polar-sparse-array.h:33
Definition polar-sparse-array-page.h:34
Definition polar-sparse-array.h:25