Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
7e00f43e
Commit
7e00f43e
authored
Mar 10, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed old array multi-implementation files now that it's all merged into
the one implementation.
parent
fb266ade
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
0 additions
and
1287 deletions
+0
-1287
array_expand_1.h
dlib/array/array_expand_1.h
+0
-170
array_expand_abstract.h
dlib/array/array_expand_abstract.h
+0
-126
array_expand_c.h
dlib/array/array_expand_c.h
+0
-139
array_kernel_1.h
dlib/array/array_kernel_1.h
+0
-651
array_sort_1.h
dlib/array/array_sort_1.h
+0
-77
array_sort_2.h
dlib/array/array_sort_2.h
+0
-65
array_sort_abstract.h
dlib/array/array_sort_abstract.h
+0
-59
No files found.
dlib/array/array_expand_1.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_EXPANd_1_
#define DLIB_ARRAY_EXPANd_1_
#include "array_expand_abstract.h"
namespace
dlib
{
template
<
typename
array_base
>
class
array_expand_1
:
public
array_base
{
typedef
typename
array_base
::
type
T
;
public
:
void
resize
(
unsigned
long
new_size
);
const
T
&
back
(
)
const
;
T
&
back
(
);
void
pop_back
(
);
void
pop_back
(
T
&
item
);
void
push_back
(
T
&
item
);
};
template
<
typename
array_base
>
inline
void
swap
(
array_expand_1
<
array_base
>&
a
,
array_expand_1
<
array_base
>&
b
)
{
a
.
swap
(
b
);
}
/*!
provides a global swap function
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_expand_1
<
array_base
>::
resize
(
unsigned
long
new_size
)
{
if
(
this
->
max_size
()
<
new_size
)
{
array_base
temp
;
temp
.
set_max_size
(
new_size
);
temp
.
set_size
(
new_size
);
for
(
unsigned
long
i
=
0
;
i
<
this
->
size
();
++
i
)
{
exchange
((
*
this
)[
i
],
temp
[
i
]);
}
temp
.
swap
(
*
this
);
}
else
{
this
->
set_size
(
new_size
);
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
typename
array_base
::
type
&
array_expand_1
<
array_base
>::
back
(
)
{
return
(
*
this
)[
this
->
size
()
-
1
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
const
typename
array_base
::
type
&
array_expand_1
<
array_base
>::
back
(
)
const
{
return
(
*
this
)[
this
->
size
()
-
1
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_expand_1
<
array_base
>::
pop_back
(
typename
array_base
::
type
&
item
)
{
exchange
(
item
,(
*
this
)[
this
->
size
()
-
1
]);
this
->
set_size
(
this
->
size
()
-
1
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_expand_1
<
array_base
>::
pop_back
(
)
{
this
->
set_size
(
this
->
size
()
-
1
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_expand_1
<
array_base
>::
push_back
(
typename
array_base
::
type
&
item
)
{
if
(
this
->
max_size
()
==
this
->
size
())
{
// double the size of the array
array_base
temp
;
temp
.
set_max_size
(
this
->
size
()
*
2
+
1
);
temp
.
set_size
(
this
->
size
()
+
1
);
for
(
unsigned
long
i
=
0
;
i
<
this
->
size
();
++
i
)
{
exchange
((
*
this
)[
i
],
temp
[
i
]);
}
exchange
(
item
,
temp
[
temp
.
size
()
-
1
]);
temp
.
swap
(
*
this
);
}
else
{
this
->
set_size
(
this
->
size
()
+
1
);
exchange
(
item
,(
*
this
)[
this
->
size
()
-
1
]);
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_EXPANd_1_
dlib/array/array_expand_abstract.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_ARRAY_EXPANd_ABSTRACT_
#ifdef DLIB_ARRAY_EXPANd_ABSTRACT_
#include "array_kernel_abstract.h"
namespace
dlib
{
template
<
typename
array_base
>
class
array_expand
:
public
array_base
{
/*!
REQUIREMENTS ON ARRAY_BASE
must be an implementation of array/array_kernel_abstract.h
POINTERS AND REFERENCES
resize() may invalidate pointers and references to internal data.
WHAT THIS EXTENSION DOES FOR ARRAY
This extension gives an array the ability to expand its size() beyond
its max_size() without clearing out all its elements. It also adds
a std::vector style push/pop back set of functions.
!*/
typedef
typename
array_base
::
type
T
;
public
:
void
resize
(
unsigned
long
new_size
);
/*!
ensures
- #size() == new_size
- #max_size() == max(new_size,max_size())
- for all i < size() && i < new_size:
- #(*this)[i] == (*this)[i]
(i.e. All the original elements of *this which were at index
values less than new_size are unmodified.)
- for all valid i >= size():
- #(*this)[i] has an undefined value
(i.e. any new elements of the array have an undefined value)
throws
- std::bad_alloc or any exception thrown by T's constructor.
If an exception is thrown then it has no effect on *this.
!*/
const
T
&
back
(
)
const
;
/*!
requires
- size() != 0
ensures
- returns a const reference to (*this)[size()-1]
!*/
T
&
back
(
);
/*!
requires
- size() != 0
ensures
- returns a non-const reference to (*this)[size()-1]
!*/
void
pop_back
(
T
&
item
);
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- swaps (*this)[size()-1] into item
- All elements with an index less than size()-1 are
unmodified by this operation.
!*/
void
pop_back
(
);
/*!
requires
- size() != 0
ensures
- #size() == size() - 1
- All elements with an index less than size()-1 are
unmodified by this operation.
!*/
void
push_back
(
T
&
item
);
/*!
ensures
- #size() == size()+1
- swaps item into (*this)[#size()-1]
- #back() == item
- #item has some undefined value (whatever happens to
get swapped out of the array)
throws
- std::bad_alloc or any exception thrown by T's constructor.
If an exception is thrown then it has no effect on *this.
!*/
};
template
<
typename
array_base
>
inline
void
swap
(
array_expand
<
array_base
>&
a
,
array_expand
<
array_base
>&
b
)
{
a
.
swap
(
b
);
}
/*!
provides a global swap function
!*/
}
#endif // DLIB_ARRAY_EXPANd_ABSTRACT_
dlib/array/array_expand_c.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2008 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_EXPAND_C_
#define DLIB_ARRAY_EXPAND_C_
#include "array_expand_abstract.h"
#include "../algs.h"
#include "../assert.h"
namespace
dlib
{
template
<
typename
array_base
>
class
array_expand_c
:
public
array_base
{
typedef
typename
array_base
::
type
T
;
public
:
const
T
&
back
(
)
const
;
T
&
back
(
);
void
pop_back
(
);
void
pop_back
(
T
&
item
);
};
template
<
typename
array_base
>
inline
void
swap
(
array_expand_c
<
array_base
>&
a
,
array_expand_c
<
array_base
>&
b
)
{
a
.
swap
(
b
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
typename
array_base
::
type
&
array_expand_c
<
array_base
>::
back
(
)
{
// make sure requires clause is not broken
DLIB_CASSERT
(
this
->
size
()
>
0
,
"
\t
T& array_expand::back()"
<<
"
\n\t
size() must be bigger than 0"
<<
"
\n\t
size(): "
<<
this
->
size
()
<<
"
\n\t
this: "
<<
this
);
// call the real function
return
array_base
::
back
();
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
const
typename
array_base
::
type
&
array_expand_c
<
array_base
>::
back
(
)
const
{
// make sure requires clause is not broken
DLIB_CASSERT
(
this
->
size
()
>
0
,
"
\t
const T& array_expand::back()"
<<
"
\n\t
size() must be bigger than 0"
<<
"
\n\t
size(): "
<<
this
->
size
()
<<
"
\n\t
this: "
<<
this
);
// call the real function
return
array_base
::
back
();
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_expand_c
<
array_base
>::
pop_back
(
)
{
// make sure requires clause is not broken
DLIB_CASSERT
(
this
->
size
()
>
0
,
"
\t
void array_expand::pop_back()"
<<
"
\n\t
size() must be bigger than 0"
<<
"
\n\t
size(): "
<<
this
->
size
()
<<
"
\n\t
this: "
<<
this
);
// call the real function
return
array_base
::
pop_back
();
}
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_expand_c
<
array_base
>::
pop_back
(
typename
array_base
::
type
&
item
)
{
// make sure requires clause is not broken
DLIB_CASSERT
(
this
->
size
()
>
0
,
"
\t
void array_expand::pop_back()"
<<
"
\n\t
size() must be bigger than 0"
<<
"
\n\t
size(): "
<<
this
->
size
()
<<
"
\n\t
this: "
<<
this
);
// call the real function
return
array_base
::
pop_back
(
item
);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_EXPAND_C_
dlib/array/array_kernel_1.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_KERNEl_1_
#define DLIB_ARRAY_KERNEl_1_
#include "array_kernel_abstract.h"
#include "../interfaces/enumerable.h"
#include "../algs.h"
#include "../serialize.h"
namespace
dlib
{
template
<
typename
T
,
typename
mem_manager
=
default_memory_manager
>
class
array_kernel_1
:
public
enumerable
<
T
>
{
/*!
INITIAL VALUE
- array_size == 0
- array_nodes == 0
- max_array_size == 0
- number_of_nodes == 0
- mask == 0
- mask_size == 0
- _at_start == true
- pos == 0
CONVENTION
- current_element_valid() == (pos != array_size)
- at_start() == _at_start
- if (pos != array_size)
- element() == (*this)[pos]
array_size == number of elements in the array.
array_nodes == pointer to array of number_of_nodes pointers.
max_array_size == the maximum allowed number of elements in the array.
mask_size == the number of bits set to 1 in mask
if (array_size > 0)
{
Only array_nodes[0] though array_nodes[(array_size-1)/number_of_nodes]
point to valid addresses. All other elements in array_nodes
are set to 0.
}
else
{
for all x: array_nodes[x] == 0
}
operator[](pos) == array_nodes[pos>>mask_size][pos&mask]
if (max_array_size == 0)
{
number_of_nodes == 0
array_nodes == 0
array_size == 0
}
!*/
public
:
typedef
T
type
;
typedef
mem_manager
mem_manager_type
;
array_kernel_1
(
)
:
array_nodes
(
0
)
{
update_max_array_size
(
0
);
}
virtual
~
array_kernel_1
(
);
void
clear
(
);
inline
const
T
&
operator
[]
(
unsigned
long
pos
)
const
;
inline
T
&
operator
[]
(
unsigned
long
pos
);
void
set_size
(
unsigned
long
size
);
inline
unsigned
long
max_size
(
)
const
;
void
set_max_size
(
unsigned
long
max
);
void
swap
(
array_kernel_1
&
item
);
// functions from the enumerable interface
inline
unsigned
long
size
(
)
const
;
inline
bool
at_start
(
)
const
;
inline
void
reset
(
)
const
;
bool
current_element_valid
(
)
const
;
inline
const
T
&
element
(
)
const
;
inline
T
&
element
(
);
bool
move_next
(
)
const
;
private
:
void
update_max_array_size
(
unsigned
long
new_max_array_size
);
/*!
ensures
- everything in the CONVENTION is satisfied
- #max_array_size == new_max_array_size
- #array_size == 0
- mask_size, mask, and number_of_nodes have been set proper
values for the new max array size
- if (new_max_array_size != 0) then
- #array_nodes == pointer to an array of size #number_of_nodes
- else
- #array_nodes == 0
- #at_start() == true
!*/
// data members
T
**
array_nodes
;
unsigned
long
max_array_size
;
unsigned
long
array_size
;
unsigned
long
number_of_nodes
;
mutable
unsigned
long
pos
;
unsigned
long
mask
;
unsigned
long
mask_size
;
mutable
bool
_at_start
;
// restricted functions
array_kernel_1
(
array_kernel_1
<
T
>&
);
// copy constructor
array_kernel_1
<
T
>&
operator
=
(
array_kernel_1
<
T
>&
);
// assignment operator
};
template
<
typename
T
,
typename
mem_manager
>
inline
void
swap
(
array_kernel_1
<
T
,
mem_manager
>&
a
,
array_kernel_1
<
T
,
mem_manager
>&
b
)
{
a
.
swap
(
b
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
serialize
(
const
array_kernel_1
<
T
,
mem_manager
>&
item
,
std
::
ostream
&
out
)
{
try
{
serialize
(
item
.
max_size
(),
out
);
serialize
(
item
.
size
(),
out
);
for
(
unsigned
long
i
=
0
;
i
<
item
.
size
();
++
i
)
serialize
(
item
[
i
],
out
);
}
catch
(
serialization_error
e
)
{
throw
serialization_error
(
e
.
info
+
"
\n
while serializing object of type array_kernel_1"
);
}
}
template
<
typename
T
,
typename
mem_manager
>
void
deserialize
(
array_kernel_1
<
T
,
mem_manager
>&
item
,
std
::
istream
&
in
)
{
try
{
unsigned
long
max_size
,
size
;
deserialize
(
max_size
,
in
);
deserialize
(
size
,
in
);
item
.
set_max_size
(
max_size
);
item
.
set_size
(
size
);
for
(
unsigned
long
i
=
0
;
i
<
size
;
++
i
)
deserialize
(
item
[
i
],
in
);
}
catch
(
serialization_error
e
)
{
item
.
clear
();
throw
serialization_error
(
e
.
info
+
"
\n
while deserializing object of type array_kernel_1"
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
array_kernel_1
<
T
,
mem_manager
>::
~
array_kernel_1
(
)
{
update_max_array_size
(
0
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
array_kernel_1
<
T
,
mem_manager
>::
clear
(
)
{
update_max_array_size
(
0
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
const
T
&
array_kernel_1
<
T
,
mem_manager
>::
operator
[]
(
unsigned
long
pos
)
const
{
return
array_nodes
[
pos
>>
mask_size
][
pos
&
mask
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
T
&
array_kernel_1
<
T
,
mem_manager
>::
operator
[]
(
unsigned
long
pos
)
{
return
array_nodes
[
pos
>>
mask_size
][
pos
&
mask
];
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
unsigned
long
array_kernel_1
<
T
,
mem_manager
>::
max_size
(
)
const
{
return
max_array_size
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
array_kernel_1
<
T
,
mem_manager
>::
set_max_size
(
unsigned
long
max
)
{
update_max_array_size
(
max
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
array_kernel_1
<
T
,
mem_manager
>::
set_size
(
unsigned
long
size
)
{
if
(
array_size
==
0
&&
size
!=
0
)
{
const
unsigned
long
new_biggest_node
=
(
size
-
1
)
/
(
mask
+
1
);
try
{
// we need to initialize some array nodes
for
(
unsigned
long
i
=
0
;
i
<=
new_biggest_node
;
++
i
)
array_nodes
[
i
]
=
new
T
[
mask
+
1
];
}
catch
(...)
{
// undo any changes
for
(
unsigned
long
i
=
0
;
i
<=
new_biggest_node
;
++
i
)
{
if
(
array_nodes
[
i
]
!=
0
)
delete
[]
array_nodes
[
i
];
array_nodes
[
i
]
=
0
;
}
throw
;
}
}
else
if
(
size
==
0
)
{
// free all nodes
for
(
unsigned
long
i
=
0
;
i
<
number_of_nodes
;
++
i
)
{
if
(
array_nodes
[
i
]
!=
0
)
delete
[]
array_nodes
[
i
];
array_nodes
[
i
]
=
0
;
}
}
else
{
const
unsigned
long
biggest_node
=
(
array_size
-
1
)
/
(
mask
+
1
);
const
unsigned
long
new_biggest_node
=
(
size
-
1
)
/
(
mask
+
1
);
try
{
if
(
biggest_node
<
new_biggest_node
)
{
// we need to initialize more array nodes
for
(
unsigned
long
i
=
biggest_node
+
1
;
i
<=
new_biggest_node
;
++
i
)
array_nodes
[
i
]
=
new
T
[
mask
+
1
];
}
else
if
(
biggest_node
>
new_biggest_node
)
{
// we need to free some array nodes
for
(
unsigned
long
i
=
new_biggest_node
+
1
;
i
<=
biggest_node
;
++
i
)
{
delete
[]
array_nodes
[
i
];
array_nodes
[
i
]
=
0
;
}
}
}
catch
(...)
{
// undo any changes
for
(
unsigned
long
i
=
biggest_node
+
1
;
i
<=
new_biggest_node
;
++
i
)
{
if
(
array_nodes
[
i
]
!=
0
)
delete
[]
array_nodes
[
i
];
array_nodes
[
i
]
=
0
;
}
throw
;
}
}
array_size
=
size
;
reset
();
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
array_kernel_1
<
T
,
mem_manager
>::
swap
(
array_kernel_1
<
T
,
mem_manager
>&
item
)
{
exchange
(
_at_start
,
item
.
_at_start
);
exchange
(
pos
,
item
.
pos
);
exchange
(
mask_size
,
item
.
mask_size
);
exchange
(
mask
,
item
.
mask
);
unsigned
long
max_array_size_temp
=
item
.
max_array_size
;
unsigned
long
array_size_temp
=
item
.
array_size
;
unsigned
long
number_of_nodes_temp
=
item
.
number_of_nodes
;
T
**
array_nodes_temp
=
item
.
array_nodes
;
item
.
max_array_size
=
max_array_size
;
item
.
array_size
=
array_size
;
item
.
number_of_nodes
=
number_of_nodes
;
item
.
array_nodes
=
array_nodes
;
max_array_size
=
max_array_size_temp
;
array_size
=
array_size_temp
;
number_of_nodes
=
number_of_nodes_temp
;
array_nodes
=
array_nodes_temp
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// private member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
array_kernel_1
<
T
,
mem_manager
>::
update_max_array_size
(
unsigned
long
new_max_array_size
)
{
max_array_size
=
new_max_array_size
;
// first free all memory
if
(
array_nodes
!=
0
)
{
for
(
unsigned
long
i
=
0
;
i
<
number_of_nodes
;
++
i
)
{
if
(
array_nodes
[
i
]
!=
0
)
delete
[]
array_nodes
[
i
];
else
break
;
}
delete
[]
array_nodes
;
}
if
(
max_array_size
>
0
)
{
// select new values for number_of_nodes, mask_size, and mask
if
(
max_array_size
<=
0x1000
)
{
number_of_nodes
=
0x10
;
mask
=
0xFF
;
mask_size
=
8
;
}
else
if
(
max_array_size
<=
0x10000
)
{
number_of_nodes
=
0x100
;
mask
=
0xFF
;
mask_size
=
8
;
}
else
if
(
max_array_size
<=
0x100000
)
{
number_of_nodes
=
1024
;
mask
=
0x3FF
;
mask_size
=
10
;
}
else
if
(
max_array_size
<=
0x1000000
)
{
number_of_nodes
=
4096
;
mask
=
0xFFF
;
mask_size
=
12
;
}
else
if
(
max_array_size
<=
0x10000000
)
{
number_of_nodes
=
16384
;
mask
=
0x3FFF
;
mask_size
=
14
;
}
else
if
(
max_array_size
<=
0x40000000
)
{
number_of_nodes
=
32768
;
mask
=
0x7FFF
;
mask_size
=
15
;
}
else
{
number_of_nodes
=
65536
;
mask
=
0xFFFF
;
mask_size
=
16
;
}
try
{
array_nodes
=
new
T
*
[
number_of_nodes
];
for
(
unsigned
long
i
=
0
;
i
<
number_of_nodes
;
++
i
)
array_nodes
[
i
]
=
0
;
}
catch
(...)
{
max_array_size
=
0
;
array_nodes
=
0
;
number_of_nodes
=
0
;
array_size
=
0
;
reset
();
throw
;
}
}
else
{
array_nodes
=
0
;
number_of_nodes
=
0
;
}
array_size
=
0
;
reset
();
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// enumerable function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
bool
array_kernel_1
<
T
,
mem_manager
>::
at_start
(
)
const
{
return
_at_start
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
void
array_kernel_1
<
T
,
mem_manager
>::
reset
(
)
const
{
_at_start
=
true
;
pos
=
array_size
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
bool
array_kernel_1
<
T
,
mem_manager
>::
current_element_valid
(
)
const
{
return
(
pos
!=
array_size
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
const
T
&
array_kernel_1
<
T
,
mem_manager
>::
element
(
)
const
{
return
operator
[](
pos
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
T
&
array_kernel_1
<
T
,
mem_manager
>::
element
(
)
{
return
operator
[](
pos
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
bool
array_kernel_1
<
T
,
mem_manager
>::
move_next
(
)
const
{
if
(
!
_at_start
)
{
if
(
pos
+
1
<
array_size
)
{
++
pos
;
return
true
;
}
else
{
pos
=
array_size
;
return
false
;
}
}
else
{
_at_start
=
false
;
pos
=
0
;
if
(
array_size
==
0
)
return
false
;
else
return
true
;
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
mem_manager
>
unsigned
long
array_kernel_1
<
T
,
mem_manager
>::
size
(
)
const
{
return
array_size
;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_KERNEl_1_
dlib/array/array_sort_1.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_SORt_1_
#define DLIB_ARRAY_SORt_1_
#include "array_sort_abstract.h"
#include "../algs.h"
#include "../sort.h"
namespace
dlib
{
template
<
typename
array_base
>
class
array_sort_1
:
public
array_base
{
typedef
typename
array_base
::
type
T
;
public
:
/*!
this is a median of three version of the QuickSort algorithm and
it swaps the entire array into a temporary C style array and sorts that and
this uses the dlib::qsort_array function
!*/
void
sort
(
);
};
template
<
typename
array_base
>
inline
void
swap
(
array_sort_1
<
array_base
>&
a
,
array_sort_1
<
array_base
>&
b
)
{
a
.
swap
(
b
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_sort_1
<
array_base
>::
sort
(
)
{
if
(
this
->
size
()
>
1
)
{
T
*
temp
=
new
T
[
this
->
size
()];
for
(
unsigned
long
i
=
0
;
i
<
this
->
size
();
++
i
)
exchange
(
temp
[
i
],(
*
this
)[
i
]);
// call the quick sort function for arrays that is in algs.h
dlib
::
qsort_array
(
temp
,
0
,
this
->
size
()
-
1
);
for
(
unsigned
long
i
=
0
;
i
<
this
->
size
();
++
i
)
exchange
((
*
this
)[
i
],
temp
[
i
]);
delete
[]
temp
;
}
this
->
reset
();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_SORt_1_
dlib/array/array_sort_2.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_ARRAY_SORt_2_
#define DLIB_ARRAY_SORt_2_
#include "array_sort_abstract.h"
#include "../algs.h"
#include "../sort.h"
namespace
dlib
{
template
<
typename
array_base
>
class
array_sort_2
:
public
array_base
{
public
:
/*!
this is a median of three version of the QuickSort algorithm and
this uses the dlib::qsort_array function
!*/
void
sort
(
);
};
template
<
typename
array_base
>
inline
void
swap
(
array_sort_2
<
array_base
>&
a
,
array_sort_2
<
array_base
>&
b
)
{
a
.
swap
(
b
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
array_base
>
void
array_sort_2
<
array_base
>::
sort
(
)
{
if
(
this
->
size
()
>
1
)
{
// call the quick sort function for arrays that is in algs.h
dlib
::
qsort_array
(
*
this
,
0
,
this
->
size
()
-
1
);
}
this
->
reset
();
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_ARRAY_SORt_2_
dlib/array/array_sort_abstract.h
deleted
100644 → 0
View file @
fb266ade
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_ARRAY_SORt_ABSTRACT_
#ifdef DLIB_ARRAY_SORt_ABSTRACT_
#include "array_kernel_abstract.h"
namespace
dlib
{
template
<
typename
array_base
>
class
array_sort
:
public
array_base
{
/*!
REQUIREMENTS ON ARRAY_BASE
- must be an implementation of array/array_kernel_abstract.h
- array_base::type must be a type with that is comparable via operator<
POINTERS AND REFERENCES
sort() may invalidate pointers and references to internal data.
WHAT THIS EXTENSION DOES FOR ARRAY
This gives an array the ability to sort its contents by calling sort().
!*/
public
:
void
sort
(
);
/*!
ensures
- for all elements in #*this the ith element is <= the i+1 element
- #at_start() == true
throws
- std::bad_alloc or any exception thrown by T's constructor
data may be lost if sort() throws
!*/
};
template
<
typename
array_base
>
inline
void
swap
(
array_sort
<
array_base
>&
a
,
array_sort
<
array_base
>&
b
)
{
a
.
swap
(
b
);
}
/*!
provides a global swap function
!*/
}
#endif // DLIB_ARRAY_SORt_ABSTRACT_
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment