OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [include/] [ustl/] [umultiset.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the uSTL library, an STL implementation.
2
//
3
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
 
6
#ifndef UMULTISET_H_446AEDBB7F61C6994DC228C25D5FA3A1
7
#define UMULTISET_H_446AEDBB7F61C6994DC228C25D5FA3A1
8
 
9
#include "uvector.h"
10
#include "ualgo.h"
11
 
12
namespace ustl {
13
 
14
/// \class multiset umultiset.h ustl.h
15
/// \ingroup AssociativeContainers
16
///
17
/// \brief Multiple sorted container.
18
/// Unlike set, it may contain multiple copies of each element.
19
///
20
template <typename T>
21
class multiset : public vector<T> {
22
public:
23
    typedef const multiset<T>&                          rcself_t;
24
    typedef vector<T>                                   base_class;
25
    typedef typename base_class::value_type             value_type;
26
    typedef typename base_class::size_type              size_type;
27
    typedef typename base_class::pointer                pointer;
28
    typedef typename base_class::const_pointer          const_pointer;
29
    typedef typename base_class::reference              reference;
30
    typedef typename base_class::const_reference        const_reference;
31
    typedef typename base_class::const_iterator         const_iterator;
32
    typedef typename base_class::iterator               iterator;
33
    typedef typename base_class::reverse_iterator       reverse_iterator;
34
    typedef typename base_class::const_reverse_iterator const_reverse_iterator;
35
public:
36
    inline                      multiset (void)         : vector<T> () {}
37
    explicit inline             multiset (size_type n)  : vector<T> (n) {}
38
    inline                      multiset (rcself_t v)   : vector<T> (v) {}
39
    inline                      multiset (const_iterator i1, const_iterator i2) : vector<T> () { insert (i1, i2); }
40
    inline rcself_t             operator= (rcself_t v)  { base_class::operator= (v); return (*this); }
41
    inline size_type            size (void) const       { return (base_class::size()); }
42
    inline iterator             begin (void)            { return (base_class::begin()); }
43
    inline const_iterator       begin (void) const      { return (base_class::begin()); }
44
    inline iterator             end (void)              { return (base_class::end()); }
45
    inline const_iterator       end (void) const        { return (base_class::end()); }
46
    inline void                 assign (const_iterator i1, const_iterator i2);
47
    size_type                   count (const_reference v) const;
48
    inline void                 push_back (const_reference v)   { insert (v); }
49
    inline iterator             insert (const_reference v);
50
    void                        insert (const_iterator i1, const_iterator i2);
51
    void                        erase (const_reference v);
52
    inline iterator             erase (iterator ep)     { return (base_class::erase (ep)); }
53
    inline iterator             erase (iterator ep1, iterator ep2) { return (base_class::erase (ep1, ep2)); }
54
    inline void                 clear (void)            { base_class::clear(); }
55
};
56
 
57
/// Copies contents of range [i1,i2)
58
template <typename T>
59
inline void multiset<T>::assign (const_iterator i1, const_iterator i2)
60
{
61
    base_class::clear();
62
    insert (i1, i2);
63
}
64
 
65
/// Returns the number of elements of value \p v.
66
template <typename T>
67
typename multiset<T>::size_type multiset<T>::count (const_reference v) const
68
{
69
    const pair<const_iterator,const_iterator> fr = equal_range (begin(), end(), v);
70
    return (distance (fr.first, fr.second));
71
}
72
 
73
/// Inserts \p v.
74
template <typename T>
75
inline typename multiset<T>::iterator multiset<T>::insert (const_reference v)
76
{
77
    iterator ip = upper_bound (begin(), end(), v);
78
    return (base_class::insert (ip, v));
79
}
80
 
81
/// Inserts all elements from range [i1,i2).
82
template <typename T>
83
void multiset<T>::insert (const_iterator i1, const_iterator i2)
84
{
85
    assert (i1 <= i2);
86
    reserve (size() + distance (i1, i2));
87
    for (; i1 < i2; ++i1)
88
        push_back (*i1);
89
}
90
 
91
/// Erases all elements with value \p v.
92
template <typename T>
93
void multiset<T>::erase (const_reference v)
94
{
95
    pair<iterator,iterator> epr = equal_range (begin(), end(), v);
96
    erase (epr.first, epr.second);
97
}
98
 
99
} // namespace ustl
100
 
101
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.