Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

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

563640 views
1
#include"typedef.h"
2
/**************************************************************************\
3
@---------------------------------------------------------------------------
4
@---------------------------------------------------------------------------
5
@ FILE: search.c
6
@---------------------------------------------------------------------------
7
@---------------------------------------------------------------------------
8
@
9
\**************************************************************************/
10
/**********************************************************************\
11
@ standard algorithms for searching vectors or matrices in
12
@ sortet lists (sorted with respect to a function comp
13
@ that compares to elements in a list.
14
@
15
@ The functions return -1, if the element is not in the list
16
@ or the integer 0<= i < List_no where i denotes the
17
@ index where the element was found in the list.
18
\**********************************************************************/
19
20
21
22
23
/**************************************************************************\
24
@---------------------------------------------------------------------------
25
@ int mat_search(M, List, List_no, comp)
26
@ matrix_TYP *M, **List;
27
@ int List_no, (*comp)();
28
@---------------------------------------------------------------------------
29
@
30
\**************************************************************************/
31
int mat_search(M, List, List_no, comp)
32
matrix_TYP *M, **List;
33
int List_no, (*comp)();
34
{
35
int low, med, high;
36
int found = FALSE
37
, test;
38
39
low = 0; high = List_no-1;
40
while(found == FALSE && low <= high)
41
{
42
med = (low + high)/2;
43
test = comp(M, List[med]);
44
if(test == 0)
45
return(med);
46
if(test > 0)
47
low = med+1;
48
else
49
high = med-1;
50
}
51
return(-1);
52
}
53
54
55
56
/**************************************************************************\
57
@---------------------------------------------------------------------------
58
@ int vec_search(M, List, List_no, dim, comp)
59
@ int *M, **List;
60
@ int List_no, dim, (*comp)();
61
@---------------------------------------------------------------------------
62
@
63
\**************************************************************************/
64
int vec_search(M, List, List_no, dim, comp)
65
int *M, **List;
66
int List_no, dim, (*comp)();
67
{
68
int low, med, high;
69
int found = FALSE, test;
70
71
low = 0; high = List_no-1;
72
while(found == FALSE && low <= high)
73
{
74
med = (low + high)/2;
75
test = comp(M, List[med], dim);
76
if(test == 0)
77
return(med);
78
if(test == 1)
79
low = med+1;
80
else
81
high = med-1;
82
}
83
return(-1);
84
}
85
86
87
88
89
/**************************************************************************\
90
@---------------------------------------------------------------------------
91
@ int pointer_mat_search(M, List, List_no, rows, cols, comp)
92
@ int **M, ***List;
93
@ int List_no, rows, cols, (*comp)();
94
@---------------------------------------------------------------------------
95
@
96
\**************************************************************************/
97
int pointer_mat_search(M, List, List_no, rows, cols, comp)
98
int **M, ***List;
99
int List_no, rows, cols, (*comp)();
100
{
101
int low, med, high;
102
int found = FALSE, test;
103
104
low = 0; high = List_no;
105
while(found == FALSE && low <= high)
106
{
107
med = (low + high)/2;
108
test = comp(M, List[med], rows, cols);
109
if(test == 0)
110
return(med);
111
if(test == 1)
112
low = med+1;
113
else
114
high = med-1;
115
}
116
return(-1);
117
}
118
119