Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
sorted_list.h
1
/*
2
* imm::sorted_list class interface
3
*
4
* This file is part of OTAWA
5
* Copyright (c) 2013, IRIT UPS.
6
*
7
* OTAWA is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* OTAWA is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with OTAWA; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
#ifndef ELM_IMM_SORTED_LIST_H_
22
#define ELM_IMM_SORTED_LIST_H_
23
24
#include <elm/compare.h>
25
#include <elm/imm/list.h>
26
#include <elm/adapter.h>
27
28
namespace
elm
{
namespace
imm {
29
30
template
<
class
T,
class
K = IdAdapter<T>,
class
C = Comparator<K> >
31
class
sorted_list
:
public
list
<T> {
32
public
:
33
34
inline
bool
contains
(
const
typename
K::t& k)
const
{
35
sorted_list<T, K, C>
l = *
this
;
36
while
(l) {
37
int
r = C::compare(k, K::key(l.
hd
()));
38
if
(r == 0)
return
true
;
39
else
if
(r < 0)
break
;
40
else
l = l.
tl
(); };
41
return
false
;
42
}
43
44
/*inline sorted_list<T, K, C> remove(const typename K::t& k) const {
45
if(isEmpty()) return *this;
46
}*/
47
/*inline bool remove(const K::t& k) const
48
{ if(list<T>::isEmpty()) return *this; }*/
49
/*if(C::compare(k, hd()) == 0) return tl(); }
50
sorted_list<T, K, C> t = tl().remove(k); if(t.node == tl().node) return *this; else return cons(hd(), t); }*/
51
52
};
53
54
} }
// elm::imm
55
56
#endif
/* ELM_IMM_SORTED_LIST_H_ */
elm::imm::sorted_list
Definition:
sorted_list.h:31
elm::imm::sorted_list::contains
bool contains(const typename K::t &k) const
Definition:
sorted_list.h:34
elm::imm::list::hd
const T & hd(void) const
Definition:
list.h:76
elm
Definition:
adapter.h:26
elm::imm::list::tl
list< T > tl(void) const
Definition:
list.h:77
elm::imm::list
Definition:
list.h:33
include
elm
imm
sorted_list.h
Generated on Fri Jul 23 2021 11:32:45 for Elm by
1.8.17