1#############################################################################
2##
3##  This file is part of GAP, a system for computational discrete algebra.
4##
5##  Copyright of GAP belongs to its developers, whose names are too numerous
6##  to list here. Please refer to the COPYRIGHT file for details.
7##
8##  SPDX-License-Identifier: GPL-2.0-or-later
9##
10
11#############################################################################
12##
13#V  IdOfFilter
14##
15##  <#GAPDoc Label="IdOfFilter">
16##  <ManSection>
17##  <Func Name="IdOfFilter" Arg="filter"/>
18##  <Func Name="IdOfFilterByName" Arg="name"/>
19##
20##  <Description>
21##  finds the id of the filter <A>filter</A>, or the id of the filter
22##  with name <A>name</A> respectively.
23##  The id of a filter is equal to the
24##  position of this filter in the global FILTERS list.
25##  <P/>
26##  Note that not every <C>filter</C> for which <C>IsFilter(filter)</C>
27##  returns <C>true</C> has an ID, only elementary filters do.
28##  </Description>
29##  </ManSection>
30##  <#/GAPDoc>
31##
32##  Note that the filter ID is stored in FLAG1_FILTER for most filters,
33##  testers have the ID stored in FLAG2_FILTER, so the code below is
34##  more efficient than just iterating over the FILTERS list.
35##
36##
37BIND_GLOBAL( "IdOfFilter",
38function(filter)
39    local fid;
40    atomic readonly FILTER_REGION do
41        fid := FLAG1_FILTER(filter);
42        if fid > 0 and FILTERS[fid] = filter then
43            return fid;
44        fi;
45        fid := FLAG2_FILTER(filter);
46        if fid > 0 and FILTERS[fid] = filter then
47            return fid;
48        fi;
49    od;
50    return fail;
51end);
52
53BIND_GLOBAL( "IdOfFilterByName",
54function(name)
55    atomic readonly FILTER_REGION do
56        return PositionProperty(FILTERS, f -> NAME_FUNC(f) = name);
57    od;
58end);
59
60#############################################################################
61##
62#V  FilterByName
63##
64##  <#GAPDoc Label="FilterByName">
65##  <ManSection>
66##  <Func Name="FilterByName" Arg="name"/>
67##
68##  <Description>
69##  finds the filter with name <A>name</A> in the global FILTERS list. This
70##  is useful to find filters that were created but not bound to a global
71##  variable.
72##  </Description>
73##  </ManSection>
74##  <#/GAPDoc>
75##
76BIND_GLOBAL( "FilterByName",
77function(name)
78    atomic readonly FILTER_REGION do
79        return First(FILTERS, f -> NAME_FUNC(f) = name);
80    od;
81end);
82