-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncircularbuffer.h
More file actions
67 lines (60 loc) · 1.86 KB
/
ncircularbuffer.h
File metadata and controls
67 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* defines ncircularbuffer functions */
#pragma once
#include "nlowlevel.copy.h"
#include "restrict.h"
namespace ncircularbuffer {
void unwrap (
double * RESTRICT dest_linear
, const double * RESTRICT src_circular
,const int size
,const int start
) {
nlowlevel::fastcopy_double( dest_linear + ( size - start ), src_circular, start );
nlowlevel::fastcopy_double( dest_linear, src_circular + start, ( size - start ) );
}
// returns new start
int unwrap_partial (
double * RESTRICT dest_linear
,const double * RESTRICT src_circular
,const int size
,const int start
,const int len
) {
if (start <= size - len) {
nlowlevel::fastcopy_double( dest_linear, src_circular + start, len );
if (start + len == size) return 0;
return start + len;
} else {
nlowlevel::fastcopy_double( dest_linear + ( size - start ), src_circular, ( len - ( size - start ) ));
nlowlevel::fastcopy_double( dest_linear, src_circular + start, ( size - start ) );
return len - (size - start);
}
}
void wrap (
double * RESTRICT dest_circular
, const double * RESTRICT src_linear
,const int size
,const int start
) {
nlowlevel::fastcopy_double( dest_circular + start, src_linear, ( size - start ) );
nlowlevel::fastcopy_double( dest_circular, src_linear + ( size - start ), start );
}
// returns new start
int wrap_partial (
double * RESTRICT dest_circular
, const double * RESTRICT src_linear
,const int size
,const int start
,const int len
) {
if (start <= size - len) {
nlowlevel::fastcopy_double( dest_circular + start, src_linear, len );
if (start + len == size) return 0;
return start + len;
} else {
nlowlevel::fastcopy_double( dest_circular + start, src_linear, ( size - start ) );
nlowlevel::fastcopy_double( dest_circular, src_linear + ( size - start ), ( len - ( size - start ) ) );
return len - (size - start);
}
}
}