summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/static_set/static_set_compare_1.h
blob: b5271e1d4d26038120fefde4bd11004afa53f4df (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_STATIC_SET_COMPARe_1_
#define DLIB_STATIC_SET_COMPARe_1_

#include "static_set_compare_abstract.h"

#include "../algs.h"



namespace dlib
{

    template <
        typename static_set_base 
        >
    class static_set_compare_1 : public static_set_base
    {

        public:

            bool operator< (
                const static_set_compare_1& rhs
            ) const;

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

    };


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

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

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

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

        static_set_base::reset();
        rhs.reset();

        return result;
    }

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

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


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

        static_set_base::reset();
        rhs.reset();

        return result;
    }

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

}

#endif // DLIB_STATIC_SET_COMPARe_1_