NEURON
getelm.cpp
Go to the documentation of this file.
1
#include <../../nrnconf.h>
2
#include <stdlib.h>
3
#include <
hocdec.h
>
4
#include "
lineq.h
"
5
6
#define diag(s) hoc_execerror(s, (char*)0);
7
8
struct
elm
*
getelm
(
struct
elm
* el,
unsigned
row
,
unsigned
col
)
9
/* return pointer to row col element maintaining order in rows */
10
{
11
struct
elm
*new_elem;
12
13
if
(el ==
ELM0
)
14
el =
rowst
[
row
];
15
/*EMPTY*/
16
if
(el ==
ELM0
);
17
else
if
(el->
col
>
col
)
18
el =
ELM0
;
19
else
20
{
21
while
( el->
c_right
!=
ELM0
&& el->
c_right
->
col
<=
col
)
22
el = el->
c_right
;
23
if
(el->
col
==
col
)
24
return
(el);
25
}
26
27
if
( (new_elem = (
struct
elm
*)malloc(
sizeof
(
struct
elm
))) ==
28
(
struct
elm
*)0)
29
diag
(
"out of space for elements"
);
30
new_elem->
row
=
row
;
31
new_elem->
col
=
col
;
32
new_elem->
value
= 0.;
33
{
34
new_elem->
r_up
=
ELM0
;
/* place new element first in column list */
35
new_elem->
r_down
=
colst
[
col
];
36
if
(
colst
[
col
] !=
ELM0
)
37
colst
[
col
]->r_up = new_elem;
38
colst
[
col
] = new_elem;
39
}
40
if
(el ==
ELM0
)
/* the new elm belongs at the beginning */
41
{
/* of the row list */
42
new_elem->
c_left
=
ELM0
;
43
new_elem->
c_right
=
rowst
[
row
];
44
if
(
rowst
[
row
] !=
ELM0
)
45
rowst
[
row
]->c_left = new_elem;
46
rowst
[
row
] = new_elem;
47
}
48
else
/* the new elm belongs after el */
49
{
50
new_elem->
c_left
= el;
51
new_elem->
c_right
= el->
c_right
;
52
el->
c_right
= new_elem;
53
if
(new_elem->
c_right
!=
ELM0
)
54
new_elem->
c_right
->
c_left
= new_elem;
55
}
56
return
(new_elem);
57
}
getelm
struct elm * getelm(struct elm *el, unsigned row, unsigned col)
Definition:
getelm.cpp:8
diag
#define diag(s)
Definition:
getelm.cpp:6
hocdec.h
lineq.h
colst
#define colst
Definition:
lineq.h:2
ELM0
#define ELM0
Definition:
lineq.h:27
rowst
#define rowst
Definition:
lineq.h:1
row
static unsigned row
Definition:
nonlin.cpp:78
elm
Definition:
lineq.h:17
elm::value
double value
Definition:
lineq.h:20
elm::col
unsigned col
Definition:
lineq.h:19
elm::c_right
struct elm * c_right
Definition:
lineq.h:24
elm::r_up
struct elm * r_up
Definition:
lineq.h:21
elm::row
unsigned row
Definition:
lineq.h:18
elm::r_down
struct elm * r_down
Definition:
lineq.h:22
elm::c_left
struct elm * c_left
Definition:
lineq.h:23
src
sparse
getelm.cpp