1 /* Siconos is a program dedicated to modeling, simulation and control
2  * of non smooth dynamical systems.
3  *
4  * Copyright 2021 INRIA.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17 */
18 #include "NSSTools.h"  // for diffns
19 
diffns(int * na,int * a,int * nb,int * b,int * nc,int * c)20 void diffns(int *na, int *a, int *nb, int * b, int *nc, int *c)
21 {
22 
23   int pta, ptb, ptc;
24   int aa, i;
25 
26   pta = 0;
27   ptb = 0;
28   ptc = 0;
29 
30   if(*nb == 0)
31   {
32 
33     for(i = 0 ; i < *na ; i++)
34       c[i] = a[i];
35     *nc  = *na;
36 
37   }
38 
39   else
40   {
41 
42     for(i = 0 ; i < *na ; i++)
43       c[i] = -1;
44 
45     while((pta < *na) && (ptb < *nb))
46     {
47 
48       aa  = a[pta];
49 
50       if(b[ptb] > aa)
51       {
52 
53         c[ptc] = aa ;
54         ptc    = ptc + 1 ;
55         pta = pta + 1;
56       }
57       else if(b[ptb] == aa)
58       {
59 
60         pta = pta + 1;
61 
62       }
63       else
64       {
65 
66         while((b[ptb] < aa) && (ptb < *nb))
67         {
68 
69 
70           ptb = ptb + 1;
71 
72           if(ptb >= *nb)
73           {
74 
75             c[ptc] = aa;
76             ptc    = ptc + 1;
77 
78             break;
79 
80           }
81         }
82 
83       }
84 
85 
86 
87     }
88 
89 
90 
91     for(i = pta + 1; i < *na ; i++)
92     {
93 
94 
95       c[ptc] = a[i];
96       ptc = ptc + 1;
97     }
98 
99     *nc = ptc;
100 
101   }
102 
103 }
104