diff options
author | Ian Jauslin <ian@jauslin.org> | 2022-06-14 09:26:07 +0200 |
---|---|---|
committer | Ian Jauslin <ian@jauslin.org> | 2022-06-14 09:46:36 +0200 |
commit | 3f0510629e422e979b57d3f93791937912a4183a (patch) | |
tree | bf2589b2689044261b0cd4d9e6b3082194fdd9e9 /src/array.c | |
parent | 469bdc80712dbf9c12562059dc4594620b59a076 (diff) |
The update to version 1.5 is rather substantial, and introduces some minor
backward-incompatibilities:
* The header "#!symbols" has been replaced by "#!virtual_fields"
* Multiplying polynomials using the '*' symbol is no longer supported (or,
rather, the symbolic capabilities of meankondo were enhanced, and the
syntax has been changed).
* 'meantools exp' has been removed (its functionality is now handled by
other means)
* 'meantoolds derive' has been replaced by 'meantools differentiate'
* The symbolic capabilities were enhanced: polynomials can now be
multiplied, added, exponentiated, and their logarithms can be taken
directly in the configuration file.
* The flow equation can now be processed after being computed using the
various "#!postprocess_*" entries.
* Deprecated kondo_preprocess.
* Compute the mean using an LU decomposition if possible.
* More detailed checks for syntax errors in configuration file.
* Check that different '#!group' entries are indeed uncorrelated.
* New flags in meankondo: '-p' and '-A'.
* New tool: meantools expand.
* Improve conversion to LaTeX using meantools-convert
* Assign terms randomly to different threads.
* Created vim files to implement syntax highlighting for configuration
files.
* Multiple bug fixes
Diffstat (limited to 'src/array.c')
-rw-r--r-- | src/array.c | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/src/array.c b/src/array.c index 11d14f7..7fb6bd8 100644 --- a/src/array.c +++ b/src/array.c @@ -1,5 +1,5 @@ /* -Copyright 2015 Ian Jauslin +Copyright 2015-2022 Ian Jauslin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -72,6 +72,14 @@ int int_array_append(int val, Int_Array* output){ return(0); } +// add a value only if it is not already present +int int_array_append_unique(int val, Int_Array* output){ + if(int_array_find(val,*output)<0){ + int_array_append(val,output); + } + return(0); +} + // concatenate int int_array_concat(Int_Array input, Int_Array* output){ int i; @@ -87,6 +95,15 @@ int int_array_concat(Int_Array input, Int_Array* output){ return(0); } +// concat but only add values that are not already present in the array +int int_array_concat_unique(Int_Array input, Int_Array* output){ + int i; + for(i=0;i<input.length;i++){ + int_array_append_unique(input.values[i],output); + } + return(0); +} + // find (does not assume the array is sorted) int int_array_find(int val, Int_Array array){ int i; @@ -199,7 +216,12 @@ int int_array_print(Int_Array array){ for(i=0;i<array.length-1;i++){ printf("%d,",array.values[i]); } - printf("%d)",array.values[array.length-1]); + if(array.length>0){ + printf("%d)",array.values[array.length-1]); + } + else{ + printf(")"); + } return(0); } @@ -334,6 +356,19 @@ int char_array_concat(Char_Array input, Char_Array* output){ return(0); } +// substring +int char_array_substring(Char_Array str, int begin, int end, Char_Array* substr){ + int i; + if(begin>end || begin<0 || end>=str.length){ + fprintf(stderr,"error: cannot extract a substring [%d,%d] from a string of length %d\n", begin, end, str.length); + exit(-1); + } + init_Char_Array(substr,end-begin); + for(i=begin;i<=end;i++){ + char_array_append(str.str[i],substr); + } + return(0); +} // convert to char* @@ -343,7 +378,7 @@ int char_array_to_str(Char_Array input, char** output){ for(i=0;i<input.length;i++){ (*output)[i]=input.str[i]; } - if((*output)[input.length-1]!='\0'){ + if(input.length==0 || (*output)[input.length-1]!='\0'){ (*output)[input.length]='\0'; } return(0); @@ -371,6 +406,34 @@ int str_to_char_array(char* str, Char_Array* output){ return(0); } +// compare char_array's +int char_array_cmp(Char_Array char_array1, Char_Array char_array2){ + int j; + if(char_array1.length!=char_array2.length){ + return(0); + } + for(j=0;j<char_array1.length && j<char_array2.length;j++){ + if(char_array1.str[j]!=char_array2.str[j]){ + return(0); + } + } + return(1); +} + +// compare a char_array and a char* +int char_array_cmp_str(Char_Array char_array, char* str){ + int j; + for(j=0;j<char_array.length && str[j]!='\0';j++){ + if(char_array.str[j]!=str[j]){ + return(0); + } + } + if(j==char_array.length && str[j]=='\0'){ + return(1); + } + return(0); +} + // format strings int char_array_snprintf(Char_Array* output, char* fmt, ...){ |