Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
bits
Commits
5705590f
Commit
5705590f
authored
Mar 23, 2019
by
Gauthier Quesnel
Browse files
snif
parent
3f9cc4d6
Pipeline
#2182
failed with stage
in 47 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/bits/array.hpp
View file @
5705590f
...
...
@@ -49,25 +49,25 @@ get_index(ID id) noexcept
}
constexpr
ID
get_
id
(
ID
id
)
noexcept
get_
key
(
ID
id
)
noexcept
{
return
id
&
0xffffffff00000000
;
}
template
<
typename
T
>
constexpr
T
get_max_
id
()
noexcept
;
get_max_
key
()
noexcept
;
template
<
>
constexpr
ID
get_max_
id
<
ID
>
()
noexcept
get_max_
key
<
ID
>
()
noexcept
{
return
0xffffffff00000000
;
}
template
<
>
constexpr
IDs
get_max_
id
<
IDs
>
()
noexcept
get_max_
key
<
IDs
>
()
noexcept
{
return
0xffff0000
;
}
...
...
@@ -103,7 +103,7 @@ get_index(IDs id) noexcept
}
constexpr
int
get_
id
(
IDs
id
)
noexcept
get_
key
(
IDs
id
)
noexcept
{
return
id
&
0xffff0000
;
}
...
...
@@ -315,7 +315,7 @@ data_array<T, Identifier>::alloc()
Do_alloc
<
T
,
Identifier
>
(
items
[
new_index
].
item
,
std
::
is_trivial
<
T
>
());
if
(
next_key
==
get_max_
id
<
Identifier
>
())
if
(
next_key
==
get_max_
key
<
Identifier
>
())
next_key
=
1
;
items
[
new_index
].
id
=
(
next_key
++
<<
16
)
|
new_index
;
...
...
include/bits/sparse-matrix.hpp
0 → 100644
View file @
5705590f
/* Copyright (C) 2018-2019 INRA
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef ORG_VLEPROJECT_BITS_SPARSE_MATRIX_HPP
#define ORG_VLEPROJECT_BITS_SPARSE_MATRIX_HPP
#include
"fixed-array.hpp"
namespace
baryonyx
{
template
<
typename
Index
>
class
sparse_matrix
{
public:
using
size_type
=
std
::
size_t
;
using
index_type
=
Index
;
struct
col_value
{
col_value
()
=
default
;
col_value
(
int
value_
,
int
row_
)
:
value
(
value_
)
,
row
(
row_
)
{}
int
value
=
-
1
;
int
row
=
-
1
;
};
struct
row_value
{
row_value
()
=
default
;
row_value
(
int
value_
,
int
column_
)
:
value
(
value_
)
,
column
(
column_
)
{}
int
value
=
-
1
;
int
column
=
-
1
;
};
protected:
using
vector_access
=
fixed_array
<
int
>
;
using
row_vector_access
=
fixed_array
<
row_value
>
;
using
col_vector_access
=
fixed_array
<
col_value
>
;
vector_access
m_rows_access
;
vector_access
m_cols_access
;
row_vector_access
m_rows_values
;
col_vector_access
m_cols_values
;
public:
using
row_iterator
=
typename
row_vector_access
::
iterator
;
using
col_iterator
=
typename
col_vector_access
::
iterator
;
using
const_row_iterator
=
typename
row_vector_access
::
const_iterator
;
using
const_col_iterator
=
typename
col_vector_access
::
const_iterator
;
explicit
sparse_matrix
(
const
int
rows
,
const
int
cols
)
:
m_rows_access
(
rows
+
1
)
,
m_cols_access
(
cols
+
1
)
{
row_vector_access
(
elem
).
swap
(
m_rows_values
);
col_vector_access
(
elem
).
swap
(
m_cols_values
);
m_rows_access
[
0
]
=
0
;
for
(
int
i
=
0
;
i
!=
rows
;
++
i
)
m_rows_access
[
i
+
1
]
=
m_rows_access
[
i
]
+
rinit
[
i
];
m_cols_access
[
0
]
=
0
;
for
(
int
i
=
0
;
i
!=
cols
;
++
i
)
m_cols_access
[
i
+
1
]
=
m_cols_access
[
i
]
+
cinit
[
i
];
}
std
::
tuple
<
row_iterator
,
row_iterator
>
row
(
int
row
)
noexcept
{
bx_expects
(
m_is_valid_index
(
row
,
0
));
row_iterator
begin
=
m_rows_values
.
begin
()
+
m_rows_access
[
row
];
row_iterator
end
=
m_rows_values
.
begin
()
+
m_rows_access
[
row
+
1
];
return
std
::
make_tuple
(
begin
,
end
);
}
std
::
tuple
<
col_iterator
,
col_iterator
>
column
(
int
col
)
noexcept
{
bx_expects
(
m_is_valid_index
(
0
,
col
));
col_iterator
begin
=
m_cols_values
.
begin
()
+
m_cols_access
[
col
];
col_iterator
end
=
m_cols_values
.
begin
()
+
m_cols_access
[
col
+
1
];
return
std
::
make_tuple
(
begin
,
end
);
}
std
::
tuple
<
const_row_iterator
,
const_row_iterator
>
row
(
int
row
)
const
noexcept
{
bx_expects
(
m_is_valid_index
(
row
,
0
));
const_row_iterator
begin
=
m_rows_values
.
begin
()
+
m_rows_access
[
row
];
const_row_iterator
end
=
m_rows_values
.
begin
()
+
m_rows_access
[
row
+
1
];
return
std
::
make_tuple
(
begin
,
end
);
}
std
::
tuple
<
const_col_iterator
,
const_col_iterator
>
column
(
int
col
)
const
noexcept
{
bx_expects
(
m_is_valid_index
(
0
,
col
));
const_col_iterator
begin
=
m_cols_values
.
begin
()
+
m_cols_access
[
col
];
const_col_iterator
end
=
m_cols_values
.
begin
()
+
m_cols_access
[
col
+
1
];
return
std
::
make_tuple
(
begin
,
end
);
}
size_type
size
()
const
noexcept
{
return
m_rows_values
.
size
();
}
int
length
()
const
noexcept
{
return
static_cast
<
int
>
(
size
());
}
private:
bool
m_is_valid_index
(
index_type
row
,
index_type
col
)
const
noexcept
{
return
col
>=
0
&&
static_cast
<
size_type
>
(
col
)
<
(
m_cols_access
.
size
()
-
1
)
&&
row
>=
0
&&
static_cast
<
size_type
>
(
row
)
<
(
m_rows_access
.
size
()
-
1
);
}
};
}
#endif
include/bits/vector.hpp
0 → 100644
View file @
5705590f
/*
* This file is part of VLE, a framework for multi-modeling, simulation
* and analysis of complex dynamical systems.
* https://www.vle-project.org
*
* Copyright (c) 2003-2018 Gauthier Quesnel <gauthier.quesnel@inra.fr>
* Copyright (c) 2003-2018 ULCO http://www.univ-littoral.fr
* Copyright (c) 2007-2018 INRA http://www.inra.fr
*
* See the AUTHORS or Authors.txt file for copyright owners and
* contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ORG_VLEPROJECT_BITS_VECTOR_HPP
#define ORG_VLEPROJECT_BITS_VECTOR_HPP
#include
<memory>
#include
<type_traits>
namespace
bits
{
template
<
typename
T
>
struct
vector
{
static_assert
(
std
::
is_trivial
<
T
>
()
==
true
);
// using this_type = vector<T>;
// using value_type = T;
// using reference = value_type&;
// using const_reference = const value_type&;
// using iterator = item*;
// using const_iterator = const item*;
// using reverse_iterator = std::reverse_iterator<iterator>;
// using const_reverse_iterator = std::reverse_iterator<const_iterator>;
// using size_type = int;
// using difference_type = int;
struct
item
{
T
item
;
int
next
;
};
using
value_type
=
item
;
using
reference
=
value_type
&
;
using
const_reference
=
const
value_type
&
;
using
iterator
=
item
*
;
using
const_iterator
=
const
item
*
;
using
reverse_iterator
=
std
::
reverse_iterator
<
iterator
>
;
using
const_reverse_iterator
=
std
::
reverse_iterator
<
const_iterator
>
;
using
size_type
=
int
;
using
difference_type
=
int
;
std
::
shared_ptr
<
item
[]
>
items
;
int
free_head
=
-
1
;
int
max_used
=
0
;
int
capacity
=
0
;
vector
(
std
::
shared_ptr
<
item
[]
>
items_
,
int
capacity_
)
noexcept
:
items
(
items_
)
,
free_head
(
-
1
)
,
max_used
(
0
)
,
capacity
(
capacity_
)
{}
vector
()
noexcept
=
default
;
~
vector
()
noexcept
=
default
;
void
init
(
std
::
shared_ptr
<
item
[]
>
items_
,
int
capacity_
)
noexcept
{
items
=
items_
;
free_head
=
-
1
;
max_used
=
0
;
capacity
=
capacity_
;
}
void
clear
()
noexcept
{
free_head
=
-
1
;
max_used
=
0
;
}
int
emplace
(
T
item
,
int
head
)
noexcept
{
int
new_index
;
if
(
free_head
<
0
)
{
new_index
=
free_head
;
free_head
=
items
[
free_head
].
next
;
}
else
{
new_index
=
max_used
++
;
}
items
[
new_index
].
item
=
item
;
items
[
new_index
].
next
=
head
;
return
new_index
;
}
int
erase_by_item
(
int
head
,
T
elem
)
noexcept
{
if
(
head
<
0
)
return
-
1
;
while
(
head
>=
0
&&
items
[
head
].
id
==
elem
)
{
auto
to_delete
=
head
;
head
=
items
[
head
].
next
;
items
[
to_delete
].
next
=
free_head
;
free_head
=
to_delete
;
}
if
(
head
<
0
)
return
-
1
;
auto
previous
=
head
;
head
=
items
[
head
].
next
;
while
(
head
>=
0
)
{
if
(
items
[
head
].
id
==
elem
)
{
auto
to_delete
=
head
;
head
=
items
[
head
].
next
;
items
[
to_delete
].
next
=
free_head
;
free_head
=
to_delete
;
}
else
{
head
=
items
[
head
].
next
;
}
previous
=
head
;
head
=
items
[
head
].
next
;
}
return
previous
;
}
int
clear
(
int
head
)
noexcept
{
while
(
head
>=
0
)
{
auto
to_delete
=
head
;
head
=
items
[
head
].
next
;
items
[
to_delete
].
next
=
free_head
;
free_head
=
to_delete
;
}
return
-
1
;
}
bool
full
()
const
noexcept
{
return
max_used
==
capacity
;
}
};
}
// bits
#endif // ORG_VLEPROJECT_BITS_VECTOR_HPP
test/flat_list.hpp
0 → 100644
View file @
5705590f
/* Copyright (C) 2019-2019 INRA
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef ORG_VLEPROJECT_BITS_FLAT_LIST_HPP
#define ORG_VLEPROJECT_BITS_FLAT_LIST_HPP
#include
"bits/array.hpp"
namespace
bits
{
template
<
typename
Object_ID
>
struct
flat_list
{
struct
item
{
item
()
=
default
;
item
(
Object_ID
id_
,
int
next_
)
:
id
(
id_
)
,
next
(
next_
)
{}
Object_ID
id
;
int
next
;
};
std
::
vector
<
item
>
items
;
int
head
=
-
1
;
flat_list
()
=
default
;
~
flat_list
()
=
default
;
void
emplace
(
Object_ID
id
)
{
items
.
emplace_back
(
id
,
head
);
head
=
(
int
)
items
.
size
();
}
void
clear
()
{
while
(
head
!=
-
1
)
{
auto
next
=
items
[
head
].
next
;
items
[
head
].
id
=
-
1
;
items
[
head
].
next
=
-
1
;
head
=
next
;
}
}
};
}
// namespace bits
#endif // ORG_VLEPROJECT_BITS_FLAT_LIST_HPP
test/vpz.cpp
View file @
5705590f
...
...
@@ -22,6 +22,7 @@
#include
<bits/array.hpp>
#include
<bits/unit-test.hpp>
#include
<bits/vector.hpp>
#include
<string>
...
...
@@ -78,18 +79,18 @@ struct Value
,
type
(
Value
::
value_type
::
none
)
{}
ID
id
;
// ID in one of the data_array of the Values structure.
ID
s
id
;
// ID in one of the data_array of the Values structure.
value_type
type
;
// The type of the identifier ID.
};
struct
Values
{
bits
::
data_array
<
std
::
int8_t
,
ID
>
integer8
;
bits
::
data_array
<
std
::
int32_t
,
ID
>
integer32
;
bits
::
data_array
<
std
::
int64_t
,
ID
>
integer64
;
bits
::
data_array
<
float
,
ID
>
real32
;
bits
::
data_array
<
double
,
ID
>
real64
;
bits
::
data_array
<
std
::
string
,
ID
>
string
;
bits
::
data_array
<
std
::
int8_t
,
ID
s
>
integer8
;
bits
::
data_array
<
std
::
int32_t
,
ID
s
>
integer32
;
bits
::
data_array
<
std
::
int64_t
,
ID
s
>
integer64
;
bits
::
data_array
<
float
,
ID
s
>
real32
;
bits
::
data_array
<
double
,
ID
s
>
real64
;
bits
::
data_array
<
std
::
string
,
ID
s
>
string
;
void
clear
(
const
Value
&
value
)
noexcept
{
...
...
@@ -135,13 +136,9 @@ struct Connection
struct
Model
{
std
::
string
name
;
ID
dynamics
;
ID
observables
;
// bits::data_array<ID> conditions;
// bits::data_array<ID> input_slots;
// bits::data_array<ID> output_slots;
// bits::data_array<ID> models;
// bits::data_array<ID> connections;
float
x
,
y
;
float
width
,
height
;
enum
class
model_type
{
...
...
@@ -171,11 +168,9 @@ struct Vpz
bits
::
data_array
<
Connection
,
IDs
>
connections
;
bits
::
data_array
<
Class
,
IDs
>
classes
;
bits
::
data_array
<
float
,
IDs
>
value_float
;
bits
::
data_array
<
double
,
IDs
>
value_double
;
bits
::
data_array
<
std
::
int8_t
,
IDs
>
value_int8
;
bits
::
data_array
<
std
::
int64_t
,
IDs
>
value_int64
;
bits
::
data_array
<
std
::
string
,
IDs
>
value_string
;
bits
::
matrix
<
IDs
>
model_dynamics
;
bits
::
matrix
<
IDs
>
model_observables
;
bits
::
matrix
<
IDs
>
model_conditions
;
};
}
// vle
...
...
@@ -184,15 +179,31 @@ int
main
(
int
/* argc */
,
char
*
/* argv */
[])
{
vle
::
Vpz
vpz
;
vpz
.
links
.
init
(
vpz
.
data_links
,
100
);
auto
&
cond
=
vpz
.
conditions
.
alloc
();
cond
.
name
=
"condition 1"
;
float
&
v1
=
vpz
.
value
_float
.
alloc
();
//
float& v2 = vpz.value
_float
.alloc();
float
&
v1
=
vpz
.
value
s
.
real32
.
alloc
();
float
&
v2
=
vpz
.
value
s
.
real32
.
alloc
();
v1
=
1.
f
;
cond
.
value
.
id
=
vpz
.
value_float
.
get_id
(
v1
);
v2
=
2.
f
;
cond
.
value
.
id
=
vpz
.
values
.
real32
.
get_id
(
v1
);
cond
.
value
.
type
=
vle
::
Value
::
value_type
::
real32
;
auto
&
mdl
=
vpz
.
models
.
alloc
();
mdl
.
name
=
"name 1"
;
mdl
.
conditions
=
vpz
.
links
.
emplace
(
vpz
.
conditions
.
get_id
(
cond
),
mdl
.
conditions
);
mdl
.
conditions
=
vpz
.
links
.
emplace
(
vpz
.
conditions
.
get_id
(
cond
),
mdl
.
conditions
);
mdl
.
conditions
=
vpz
.
links
.
emplace
(
vpz
.
conditions
.
get_id
(
cond
),
mdl
.
conditions
);
mdl
.
conditions
=
vpz
.
links
.
emplace
(
vpz
.
conditions
.
get_id
(
cond
),
mdl
.
conditions
);
return
unit_test
::
report_errors
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment