Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87906332
discret.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Oct 15, 16:32
Size
2 KB
Mime Type
text/x-c
Expires
Thu, Oct 17, 16:32 (2 d)
Engine
blob
Format
Raw Data
Handle
21678241
Attached To
rSTICAZZI yearII_reports
discret.cpp
View Options
#include "discret.h"
#include "regex.h"
interval
::
interval
(
const
std
::
initializer_list
<
discret
>&
list
)
:
L
(
0
),
points
(
list
)
{
// last point
if
(
points
.
size
()
>
0
)
L
=
(
*
points
.
rbegin
()).
b
;
}
void
interval
::
push
(
const
discret
&
d
)
{
points
.
insert
(
d
);
}
interval
&
interval
::
operator
<<
(
const
discret
&
d
)
{
push
(
d
);
return
*
this
;
}
double
interval
::
operator
[](
std
::
size_t
i
)
const
{
double
a
=
0
;
for
(
const
auto
&
d
:
points
)
{
if
(
i
<
d
.
N
)
return
a
+
i
*
(
d
.
b
-
a
)
/
d
.
N
;
i
-=
d
.
N
;
a
=
d
.
b
;
}
return
L
;
}
double
interval
::
operator
[](
double
alpha
)
const
{
double
t
=
alpha
-
int
(
alpha
);
std
::
size_t
k
=
static_cast
<
std
::
size_t
>
(
alpha
);
return
t
*
(
*
this
)[
k
+
1
]
+
(
1
-
t
)
*
(
*
this
)[
k
];
}
std
::
size_t
interval
::
N
()
const
{
std
::
size_t
out
(
0
);
for
(
auto
d
:
points
)
out
+=
d
.
N
;
return
out
;
}
std
::
size_t
interval
::
N
(
std
::
size_t
i
)
const
{
for
(
auto
d
:
points
)
{
if
(
i
--
==
0
)
return
d
.
N
;
}
return
0
;
}
double
interval
::
border
(
std
::
size_t
i
)
const
{
for
(
auto
d
:
points
)
{
if
(
i
--
==
0
)
return
d
.
b
;
}
return
0
;
}
std
::
set
<
interval
::
discret
>::
iterator
interval
::
begin
()
{
return
points
.
begin
();
}
std
::
set
<
interval
::
discret
>::
const_iterator
interval
::
begin
()
const
{
return
points
.
begin
();
}
std
::
set
<
interval
::
discret
>::
iterator
interval
::
end
()
{
return
points
.
end
();
}
std
::
set
<
interval
::
discret
>::
const_iterator
interval
::
end
()
const
{
return
points
.
end
();
}
bool
interval
::
discret
::
operator
<
(
const
interval
::
discret
&
other
)
const
{
return
b
<
other
.
b
;
}
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
interval
::
discret
&
d
)
{
return
regex
::
parse
(
is
,
regex
::
term
::
brack
,
d
.
b
,
d
.
N
);
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
interval
::
discret
&
d
)
{
return
regex
::
print
(
os
,
regex
::
term
::
brack
,
d
.
b
,
d
.
N
);
}
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
interval
&
obj
)
{
return
regex
::
vparse
<
interval
::
discret
>
(
is
,
regex
::
term
::
brack
,
obj
);
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
interval
&
obj
)
{
return
regex
::
vprint
(
os
,
regex
::
term
::
brack
,
obj
);
}
Event Timeline
Log In to Comment