|
ContainersMany of these containers were inspired by the RESOLVE/C++ course sequence at Ohio State. As such, most of the objects do not support copying in any form, only swapping is allowed. That is, when objects are added or removed from any of these containers they are swapped in and out, not copied. This allows you to do things like have containers of containers of containers without encountering the overhead of the massive copying that would likely result if you did the same thing with the STL. It also means you can store objects that are not copyable inside these containers, which is not something you can do with the STL.
To use any of these containers all you need to do is #include the file indicated in the
short section about the component you would like to use. Then pick which implementation you
would like and typedef it to something nice. Here is an example of creating a typedef for
a set of integers using the first kernel implementation. Note that it is assumed by these containers that swap() and operator< do not throw. They may not function correctly if this assumption is broken. Also note that the built in types (int, long, char, etc.) and std::string will not cause operator< or swap() to throw. Note also that most of the containers inherit from the enumerable interface. Thus, all the member functions inherited from enumerable are defined in the enumerable class and their documentation is not repeated in each container's documentation. This includes the size() member function in each container. |
|
It is somewhat like the type_safe_union except you don't have to declare the set of possible content types beforehand. So in some sense this is like a less type-strict version of the type_safe_union.
It is intended to be used to contain dlib::decision_function objects and other types which represent learned decision functions. It allows you to write code which contains and processes these decision functions without needing to know the specific types of decision functions used.
decision_function train( const std::vector<sample_type>& samples, const std::vector<scalar_type>& labels ) constWhere decision_function is a type capable of being stored in an any_decision_function object.
any_trainer is intended to be used to contain objects such as the svm_nu_trainer and other similar types which represent supervised machine learning algorithms. It allows you to write code which contains and processes these trainer objects without needing to know the specific types of trainer objects used.
array_kernel_1:
This implementation is done using an array of pointers, each of which point to small sections of the array. This implementation allows the array to use only about as much memory as it needs at any given time. It does not use the memory_manager at all.
kernel_1ais a typedef for array_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
array_kernel_2:
This implementation is done using a single array of max_size() elements. So this is just a simple layer on top of a C style array. It uses the memory_manager for all memory allocations.
kernel_2ais a typedef for array_kernel_2 kernel_2a_cis a typedef for kernel_2a that checks its preconditions.
array_expand_1:
This is implemented by creating a new bigger array if max_size() isn't big enough, swapping everything into that new array, and then swapping that array with *this.
expand_1ais a typedef for array_sort_1a extended by array_expand_1 expand_1a_cis a typedef for expand_1a that checks its preconditions. expand_1bis a typedef for array_sort_1b extended by array_expand_1 expand_1b_cis a typedef for expand_1b that checks its preconditions. expand_1cis a typedef for array_sort_2a extended by array_expand_1 expand_1c_cis a typedef for expand_1c that checks its preconditions. expand_1dis a typedef for array_sort_2b extended by array_expand_1 expand_1d_cis a typedef for expand_1d that checks its preconditions.
array_sort_1:
This is a version of the QuickSort algorithm. It swaps the entire array into a C style array, sorts it and then swaps it back into the array object.
sort_1ais a typedef for array_kernel_1a extended by array_sort_1 sort_1a_cis a typedef for sort_1a that checks its preconditions. sort_1bis a typedef for array_kernel_2a extended by array_sort_1 sort_1b_cis a typedef for sort_1b that checks its preconditions.
array_sort_2:
This is a version of the QuickSort algorithm.
sort_2ais a typedef for array_kernel_1a extended by array_sort_2 sort_2a_cis a typedef for sort_2a that checks its preconditions. sort_2bis a typedef for array_kernel_2a extended by array_sort_2 sort_2b_cis a typedef for sort_2b that checks its preconditions.
array2d_kernel_1:
This is implemented in the obvious way. See the source for details. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for array2d_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
binary_search_tree_kernel_1:
This implementation is done using an AVL binary search tree. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for binary_search_tree_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
binary_search_tree_kernel_2:
This implementation is done using a red-black binary search tree. It uses the memory_manager for all memory allocations.
kernel_2ais a typedef for binary_search_tree_kernel_2 kernel_2a_cis a typedef for kernel_2a that checks its preconditions.
directed_graph_kernel_1:
This is implemented using std::vector to contain all the nodes and edges.
kernel_1ais a typedef for directed_graph_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
graph_kernel_1:
This is implemented using std::vector to contain all the nodes and edges.
kernel_1ais a typedef for graph_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
hash_map_kernel_1:
This implementation is done using a hash_table object. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for hash_map_kernel_1 that uses hash_table_kernel_1a kernel_1a_cis a typedef for kernel_1a that checks its preconditions. kernel_1bis a typedef for hash_map_kernel_1 that uses hash_table_kernel_2a kernel_1b_cis a typedef for kernel_1b that checks its preconditions. kernel_1cis a typedef for hash_map_kernel_1 that uses hash_table_kernel_2b kernel_1c_cis a typedef for kernel_1c that checks its preconditions.
hash_set_kernel_1:
This implementation is done using a hash_table object. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for hash_set_kernel_1 that uses hash_table_kernel_1a kernel_1a_cis a typedef for kernel_1a that checks its preconditions. kernel_1bis a typedef for hash_set_kernel_1 that uses hash_table_kernel_2a kernel_1b_cis a typedef for kernel_1b that checks its preconditions. kernel_1cis a typedef for hash_set_kernel_1 that uses hash_table_kernel_2b kernel_1c_cis a typedef for kernel_1c that checks its preconditions.
hash_table_kernel_1:
This implementation is done using singly linked lists as hashing buckets. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for hash_table_kernel_1. kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
hash_table_kernel_2:
This implementation is done using binary_search_tree objects as hashing buckets. It uses the memory_manager for all memory allocations.
kernel_2ais a typedef for hash_table_kernel_2 that uses binary_search_tree_kernel_1 kernel_2a_cis a typedef for kernel_2a that checks its preconditions. kernel_2bis a typedef for hash_table_kernel_2 that uses binary_search_tree_kernel_2 kernel_2b_cis a typedef for kernel_2b that checks its preconditions.
map_kernel_1:
This is implemented using the binary_search_tree component. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for map_kernel_1 that uses binary_search_tree_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions. kernel_1bis a typedef for map_kernel_1 that uses binary_search_tree_kernel_2 kernel_1b_cis a typedef for kernel_1b that checks its preconditions.
This object is also capable of using BLAS and LAPACK libraries such as ATLAS or the Intel MKL when available. To enable BLAS support all you have to do is #define DLIB_USE_BLAS and then make sure you link your application with your BLAS library. Similarly, to enable LAPACK support just #define DLIB_USE_LAPACK and link to your LAPACK library. Finally, the use of BLAS and LAPACK is transparent to the user, that is, the dlib matrix object uses BLAS and LAPACK internally to optimize various operations while still allowing the user to use a simple MATLAB like syntax.
Note that the cmake files that come with dlib know how to link a project with ATLAS or the Intel MKL if you are building on a linux system. The cmake files may also work in a few other cases as well but I haven't tested any others. But in any case, by no means are you required to use the dlib cmake files.
It is also worth noting that all the preconditions of every function related to the matrix object are checked by DLIB_ASSERT statements and thus can be enabled by #defining ENABLE_ASSERTS or DEBUG. Doing this will cause your program to run slower but should catch any usage errors.
Finally, you don't need to #include anything to get the matrix extensions listed below. They are included by the dlib/matrix.h file for you.
queue_kernel_1:
This is implemented in the obvious way using a singly linked list. It does not use the memory_manager at all.
kernel_1ais a typedef for queue_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
queue_kernel_2:
This is implemented using a singly linked list and each node in the list contains block_size (a template parameter) elements. It uses the memory_manager for all memory allocations.
kernel_2ais a typedef for queue_kernel_2 with a block_size of 20 kernel_2a_cis a typedef for kernel_2a that checks its preconditions. kernel_2bis a typedef for queue_kernel_2 with a block_size of 100 kernel_2b_cis a typedef for kernel_2b that checks its preconditions.
queue_sort_1:
This is a version of the QuickSort algorithm.
sort_1ais a typedef for queue_kernel_1a extended by queue_sort_1 sort_1a_cis a typedef for sort_1a that checks its preconditions. sort_1bis a typedef for queue_kernel_2a extended by queue_sort_1 sort_1b_cis a typedef for sort_1b that checks its preconditions. sort_1cis a typedef for queue_kernel_2b extended by queue_sort_1 sort_1c_cis a typedef for sort_1c that checks its preconditions.
reference_counter_kernel_1:
This implementation is done using pointers in the obvious way.
kernel_1ais a typedef for reference_counter_kernel_1
sequence_kernel_1:
This is implemented as an AVL binary search tree. Accessing(or adding or removing) an element always takes O(log n) time. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for sequence_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
sequence_kernel_2:
This implementation is done using a doubly linked list in the shape of a ring. It will remember the last element accessed(or added or removed) and give O(1) access time to the elements just left and right of it. Aside from that, accessing(or adding or removing) a random element will take O(n) and in the worst case it will take time proportional to the size of the sequence/2.It does not use the memory_manager at all.
kernel_2ais a typedef for sequence_kernel_2 kernel_2a_cis a typedef for kernel_2a that checks its preconditions.
sequence_compare_1:
The implementation is obvious. Click on the sequence_compare_1 link if you want to see.
compare_1ais a typedef for sequence_kernel_1a extended by sequence_compare_1 compare_1a_cis a typedef for compare_1a that checks its preconditions. compare_1bis a typedef for sequence_kernel_2a extended by sequence_compare_1 compare_1b_cis a typedef for compare_1b that checks its preconditions.
sequence_sort_1:
This is a version of the QuickSort algorithm and it sorts sequences of less than 30 elements with a selection sort. This implementation is fastest when used with sequence_kernel_2 and fairly slow when used with sequence_kernel_1
sort_1ais a typedef for sequence_kernel_2a extended by sequence_sort_1 sort_1a_cis a typedef for sort_1a that checks its preconditions.
sequence_sort_2:
This is a version of the QuickSort algorithm. This implementation of sort is the best to use with sequence_kernel_1 objects but gives extremely poor performance with sequence_kernel_2 objects.
sort_2ais a typedef for sequence_kernel_1a extended by sequence_sort_2 sort_2a_cis a typedef for sort_2a that checks its preconditions.
set_kernel_1:
This is implemented using the binary_search_tree component. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for set_kernel_1 that uses binary_search_tree_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions. kernel_1bis a typedef for set_kernel_1 that uses binary_search_tree_kernel_2 kernel_1b_cis a typedef for kernel_1b that checks its preconditions.
set_compare_1:
The implementation is obvious. Click on the set_compare_1 link if you want to see.
compare_1ais a typedef for set_kernel_1a extended by set_compare_1 compare_1a_cis a typedef for compare_1a that checks its preconditions. compare_1bis a typedef for set_kernel_1b extended by set_compare_1 compare_1b_cis a typedef for compare_1b that checks its preconditions.
This object represents a reference counted smart pointer. Each shared_ptr contains a pointer to some object and when the last shared_ptr that points to the object is destructed or reset() then the object is guaranteed to be deleted.
This is an implementation of the std::tr1::shared_ptr template from the document ISO/IEC PDTR 19768, Proposed Draft Technical Report on C++ Library Extensions. The only deviation from that document is that this shared_ptr is declared inside the dlib namespace rather than std::tr1.
This object represents a reference counted smart pointer just like shared_ptr except that it is threadsafe.
sliding_buffer_kernel_1:
This object is implemented using a C style array in the obvious way. See the code for details.
kernel_1ais a typedef for sliding_buffer_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
stack_kernel_1:
This implementation is done in the obvious way using a singly linked list. It uses the memory_manager for all memory allocations.
kernel_1ais a typedef for stack_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
static_map_kernel_1:
This implementation is just a sorted array which can be searched using a binary search.
kernel_1ais a typedef for static_map_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
static_set_kernel_1:
This implementation is just a sorted array which can be searched using a binary search.
kernel_1ais a typedef for static_set_kernel_1 kernel_1a_cis a typedef for kernel_1a that checks its preconditions.
static_set_compare_1:
The implementation is obvious. Click on the static_set_compare_1 link if you want to see.
compare_1ais a typedef for static_set_kernel_1a extended by static_set_compare_1 compare_1a_cis a typedef for compare_1a that checks its preconditions.
Note that there is only one implementation of this object so there aren't any different kernels to choose from when you create instances of the tuple object. So for example, you could declare a tuple of 3 ints using the following statement: dlib::tuple<int,int,int> t;
It is also implemented without performing any heap memory allocations and instead it stores everything on the stack.
The weak_ptr class template stores a weak reference to an object that is already managed by a shared_ptr. To access the object, a weak_ptr can be converted to a shared_ptr using the member function lock().
This is an implementation of the std::tr1::weak_ptr template from the document ISO/IEC PDTR 19768, Proposed Draft Technical Report on C++ Library Extensions. The only deviation from that document is that this shared_ptr is declared inside the dlib namespace rather than std::tr1.