CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
/***************************************************************************
2
**
3
*A gauss.c gauss-package Max Neunhoeffer
4
**
5
*/
6
7
/* Try to use as much of the GNU C library as possible: */
8
#define _GNU_SOURCE
9
10
#include "src/compiled.h" /* GAP headers */
11
12
/* The following seems to be necessary to run under modern gcc compilers
13
* which have the ssp stack checking enabled. Hopefully this does not
14
* hurt in future or other versions... */
15
#if 0
16
#ifdef __GNUC__
17
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
18
extern void __stack_chk_fail();
19
void __stack_chk_fail_local (void)
20
{
21
__stack_chk_fail ();
22
}
23
#endif
24
#endif
25
#endif
26
27
Obj FuncSYMMETRIC_DIFFERENCE_OF_ORDERED_SETS_OF_SMALL_INTEGERS( Obj self, Obj a, Obj b )
28
{
29
Obj c; /* for the result */
30
Int len,lena,lenb;
31
Int i,j,k;
32
Int x,y;
33
34
lena = LEN_PLIST(a);
35
lenb = LEN_PLIST(b);
36
len = lena+lenb;
37
if (len == 0) {
38
return NEW_PLIST(T_PLIST_EMPTY,0);
39
}
40
c = NEW_PLIST(T_PLIST_CYC_SSORT,len);
41
SET_LEN_PLIST(c,len);
42
i = 1;
43
j = 1;
44
k = 1;
45
if (i <= lena && j <= lenb) {
46
x = INT_INTOBJ(ELM_PLIST(a,i));
47
y = INT_INTOBJ(ELM_PLIST(b,j));
48
while (1) {
49
if (x < y) {
50
SET_ELM_PLIST(c,k,INTOBJ_INT(x));
51
k++;
52
i++;
53
if (i > lena)
54
break;
55
else
56
x = INT_INTOBJ(ELM_PLIST(a,i));
57
} else if (y < x) {
58
SET_ELM_PLIST(c,k,INTOBJ_INT(y));
59
k++;
60
j++;
61
if (j > lenb)
62
break;
63
else
64
y = INT_INTOBJ(ELM_PLIST(b,j));
65
} else {
66
i++;
67
j++;
68
if (i > lena)
69
break;
70
else
71
x = INT_INTOBJ(ELM_PLIST(a,i));
72
if (j > lenb)
73
break;
74
else
75
y = INT_INTOBJ(ELM_PLIST(b,j));
76
}
77
}
78
}
79
/* Only one of the following will happen: */
80
while (i <= lena) {
81
SET_ELM_PLIST(c,k,ELM_PLIST(a,i));
82
i++;
83
k++;
84
}
85
while (j <= lenb) {
86
SET_ELM_PLIST(c,k,ELM_PLIST(b,j));
87
j++;
88
k++;
89
}
90
SET_LEN_PLIST(c,k-1);
91
SHRINK_PLIST(c,k-1);
92
return c;
93
}
94
95
96
/*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * */
97
98
/******************************************************************************
99
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
100
*/
101
static StructGVarFunc GVarFuncs [] = {
102
103
{ "SYMMETRIC_DIFFERENCE_OF_ORDERED_SETS_OF_SMALL_INTEGERS", 2, "a, b",
104
FuncSYMMETRIC_DIFFERENCE_OF_ORDERED_SETS_OF_SMALL_INTEGERS,
105
"gauss.c:SYMMETRIC_DIFFERENCE_OF_ORDERED_SETS_OF_SMALL_INTEGERS" },
106
107
{ 0 }
108
109
};
110
111
/******************************************************************************
112
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
113
*/
114
static Int InitKernel ( StructInitInfo *module )
115
{
116
/* init filters and functions */
117
InitHdlrFuncsFromTable( GVarFuncs );
118
119
/* return success */
120
return 0;
121
}
122
123
/******************************************************************************
124
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
125
*/
126
static Int InitLibrary ( StructInitInfo *module )
127
{
128
/* init functions */
129
InitGVarFuncsFromTable(GVarFuncs);
130
131
/* return success */
132
return 0;
133
}
134
135
/******************************************************************************
136
*F InitInfopl() . . . . . . . . . . . . . . . . . table of init functions
137
*/
138
static StructInitInfo module = {
139
#ifdef GAUSSSTATIC
140
.type = MODULE_STATIC,
141
#else
142
.type = MODULE_DYNAMIC,
143
#endif
144
.name = "gauss",
145
.initKernel = InitKernel,
146
.initLibrary = InitLibrary,
147
};
148
149
#ifndef GAUSSSTATIC
150
StructInitInfo * Init__Dynamic ( void )
151
{
152
return &module;
153
}
154
#endif
155
156
StructInitInfo * Init__gauss ( void )
157
{
158
return &module;
159
}
160
161
162
/*
163
*
164
* This program is free software; you can redistribute it and/or modify
165
* it under the terms of the GNU General Public License as published by
166
* the Free Software Foundation; version 2 of the License.
167
*
168
* This program is distributed in the hope that it will be useful,
169
* but WITHOUT ANY WARRANTY; without even the implied warranty of
170
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
171
* GNU General Public License for more details.
172
*
173
* You should have received a copy of the GNU General Public License
174
* along with this program; if not, write to the Free Software
175
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
176
*
177
*/
178
179