summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/set/set_compare_1.h
blob: d4b5e76cab83e53bc80f686777def88e5b4c3a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (C) 2005  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#ifndef DLIB_SET_COMPARe_1_
#define DLIB_SET_COMPARe_1_

#include "set_compare_abstract.h"

#include "../algs.h"



namespace dlib
{

    template <
        typename set_base 
        >
    class set_compare_1 : public set_base
    {

        public:

            bool operator< (
                const set_compare_1& rhs
            ) const;

            bool operator== (
                const set_compare_1& rhs
            ) const;

    };


    template <
        typename set_base
        >
    inline void swap (
        set_compare_1<set_base>& a, 
        set_compare_1<set_base>& b 
    ) { a.swap(b); }  

// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
    // member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------

    template <
        typename set_base
        >
    bool set_compare_1<set_base>::
    operator< (
        const set_compare_1<set_base>& rhs
    ) const
    {
        bool result = false;
        if (set_base::size() < rhs.size())
            result = true;

        if (set_base::size() == rhs.size())
        {
            rhs.reset();
            set_base::reset();
            while (rhs.move_next())
            {
                set_base::move_next();
                if (set_base::element() < rhs.element())
                {
                    result = true;
                    break;
                }
                else if (rhs.element() < set_base::element())
                {
                    break;
                }
            }            
        }

        set_base::reset();
        rhs.reset();

        return result;
    }

// ----------------------------------------------------------------------------------------

    template <
        typename set_base
        >
    bool set_compare_1<set_base>::
    operator== (
        const set_compare_1<set_base>& rhs
    ) const
    {
        bool result = true;
        if (set_base::size() != rhs.size())
            result = false;


        rhs.reset();
        set_base::reset();
        while (rhs.move_next() && set_base::move_next())
        {            
            if (!(rhs.element() == set_base::element()))
            {
                result = false;
                break;
            }
        }

        set_base::reset();
        rhs.reset();

        return result;
    }

// ----------------------------------------------------------------------------------------

}

#endif // DLIB_SET_COMPARe_1_