Ian Jauslin
summaryrefslogtreecommitdiff
path: root/src/rcc.c
diff options
context:
space:
mode:
authorIan Jauslin <ian.jauslin@roma1.infn.it>2015-06-14 00:52:45 +0000
committerIan Jauslin <ian.jauslin@roma1.infn.it>2015-06-14 00:52:45 +0000
commitaa0f3ae2988d372b190b9bde2e75a6d17e744e93 (patch)
tree14482245c2fca27fcdad3078e97d0871352d52a7 /src/rcc.c
Initial commitv1.2
Diffstat (limited to 'src/rcc.c')
-rw-r--r--src/rcc.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/rcc.c b/src/rcc.c
new file mode 100644
index 0000000..484e20a
--- /dev/null
+++ b/src/rcc.c
@@ -0,0 +1,95 @@
+/*
+Copyright 2015 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "rcc.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "array.h"
+
+// init
+int init_RCC(RCC* rccs, int size){
+ (*rccs).values=calloc(size,sizeof(long double));
+ (*rccs).indices=calloc(size,sizeof(int));
+ (*rccs).length=size;
+ return(0);
+}
+
+int free_RCC(RCC rccs){
+ free(rccs.values);
+ free(rccs.indices);
+ return(0);
+}
+
+// set a given element of an rcc
+int RCC_set_elem(long double value, int index, RCC* rcc, int pos){
+ (*rcc).values[pos]=value;
+ (*rcc).indices[pos]=index;
+ return(0);
+}
+
+int RCC_cpy(RCC input,RCC* output){
+ int i;
+
+ init_RCC(output,input.length);
+ for(i=0;i<input.length;i++){
+ RCC_set_elem(input.values[i], input.indices[i], output, i);
+ }
+ return(0);
+}
+
+// concatenate rccs
+int RCC_concat(RCC rccs1, RCC rccs2, RCC* output){
+ int i;
+
+ init_RCC(output,rccs1.length+rccs2.length);
+
+ for(i=0;i<rccs1.length;i++){
+ RCC_set_elem(rccs1.values[i], rccs1.indices[i], output, i);
+ }
+
+ for(i=0;i<rccs2.length;i++){
+ RCC_set_elem(rccs2.values[i], rccs2.indices[i], output, i+rccs1.length);
+ }
+
+ return(0);
+}
+
+// append an rcc at the end of another
+int RCC_append(RCC input, RCC* output){
+ int i;
+ for(i=0;i<input.length;i++){
+ RCC_set_elem(input.values[i], input.indices[i], output, i+(*output).length);
+ }
+ (*output).length+=input.length;
+ return(0);
+}
+
+// print an rcc vector with maximal precision
+int RCC_print(RCC rccs){
+ int j;
+
+ for(j=0;j<rccs.length;j++){
+ printf("%d:%.19Le",rccs.indices[j],rccs.values[j]);
+ if(j<rccs.length-1){
+ printf(",\n");
+ }
+ else{
+ printf("\n");
+ }
+ }
+
+ return(0);
+}