GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include"typedef.h"1/**************************************************************************\2@---------------------------------------------------------------------------3@---------------------------------------------------------------------------4@ FILE: search.c5@---------------------------------------------------------------------------6@---------------------------------------------------------------------------7@8\**************************************************************************/9/**********************************************************************\10@ standard algorithms for searching vectors or matrices in11@ sortet lists (sorted with respect to a function comp12@ that compares to elements in a list.13@14@ The functions return -1, if the element is not in the list15@ or the integer 0<= i < List_no where i denotes the16@ index where the element was found in the list.17\**********************************************************************/1819202122/**************************************************************************\23@---------------------------------------------------------------------------24@ int mat_search(M, List, List_no, comp)25@ matrix_TYP *M, **List;26@ int List_no, (*comp)();27@---------------------------------------------------------------------------28@29\**************************************************************************/30int mat_search(M, List, List_no, comp)31matrix_TYP *M, **List;32int List_no, (*comp)();33{34int low, med, high;35int found = FALSE36, test;3738low = 0; high = List_no-1;39while(found == FALSE && low <= high)40{41med = (low + high)/2;42test = comp(M, List[med]);43if(test == 0)44return(med);45if(test > 0)46low = med+1;47else48high = med-1;49}50return(-1);51}52535455/**************************************************************************\56@---------------------------------------------------------------------------57@ int vec_search(M, List, List_no, dim, comp)58@ int *M, **List;59@ int List_no, dim, (*comp)();60@---------------------------------------------------------------------------61@62\**************************************************************************/63int vec_search(M, List, List_no, dim, comp)64int *M, **List;65int List_no, dim, (*comp)();66{67int low, med, high;68int found = FALSE, test;6970low = 0; high = List_no-1;71while(found == FALSE && low <= high)72{73med = (low + high)/2;74test = comp(M, List[med], dim);75if(test == 0)76return(med);77if(test == 1)78low = med+1;79else80high = med-1;81}82return(-1);83}8485868788/**************************************************************************\89@---------------------------------------------------------------------------90@ int pointer_mat_search(M, List, List_no, rows, cols, comp)91@ int **M, ***List;92@ int List_no, rows, cols, (*comp)();93@---------------------------------------------------------------------------94@95\**************************************************************************/96int pointer_mat_search(M, List, List_no, rows, cols, comp)97int **M, ***List;98int List_no, rows, cols, (*comp)();99{100int low, med, high;101int found = FALSE, test;102103low = 0; high = List_no;104while(found == FALSE && low <= high)105{106med = (low + high)/2;107test = comp(M, List[med], rows, cols);108if(test == 0)109return(med);110if(test == 1)111low = med+1;112else113high = med-1;114}115return(-1);116}117118119