161 lines
14 KiB
MQL5
161 lines
14 KiB
MQL5
|
#ifndef LIB_MQLPLUS_OBJ_MAP_RBTREE_TEMPLATES_MQH_INCLUDED
|
||
|
#define LIB_MQLPLUS_OBJ_MAP_RBTREE_TEMPLATES_MQH_INCLUDED
|
||
|
#property version "1.0";
|
||
|
/**********************************************************************************
|
||
|
* Copyright (C) 2010-2022 Dominik Egert <info@freie-netze.de>
|
||
|
*
|
||
|
* This file is the objects include file.
|
||
|
*
|
||
|
* MQLplus, including this file may not be copied and/or distributed
|
||
|
* without explecit permit by the author.
|
||
|
* Author Dominik Egert / Freie Netze UG.
|
||
|
**********************************************************************************
|
||
|
*
|
||
|
* Version: 1.0
|
||
|
* State: production
|
||
|
*
|
||
|
* File information
|
||
|
* ================
|
||
|
*
|
||
|
*
|
||
|
*
|
||
|
*/
|
||
|
#ifdef DBG_MSG_TRACE_FILE_LOADER
|
||
|
DBG_MSG_TRACE_FILE_LOADER;
|
||
|
|
||
|
#endif
|
||
|
|
||
|
|
||
|
|
||
|
// Incluse base object
|
||
|
#include "nodes/lib_obj_node_map_rbtree.mqh"
|
||
|
#include "base/lib_base_map.mqh"
|
||
|
|
||
|
|
||
|
|
||
|
/*********************************************************************************************************************************************************/
|
||
|
/* */
|
||
|
/* MQLplus data structures */
|
||
|
/* */
|
||
|
/*********************************************************************************************************************************************************/
|
||
|
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
//
|
||
|
// Red Black Tree object
|
||
|
//
|
||
|
|
||
|
// Derived simple type class object
|
||
|
#define NODE_TYPE object_map_node<USER_DATA, USER_KEY>
|
||
|
#define MAP_TYPE _map<USER_DATA, USER_KEY, NODE_TYPE>
|
||
|
|
||
|
template <typename USER_DATA, typename USER_KEY>
|
||
|
struct map : public MAP_TYPE
|
||
|
{
|
||
|
// Constructors / Destructor
|
||
|
map() : MAP_TYPE() { };
|
||
|
map(const map<USER_DATA, USER_KEY>& p_in) : MAP_TYPE(p_in) { };
|
||
|
~map() { };
|
||
|
|
||
|
// Assignment operator
|
||
|
void operator=(const map<USER_DATA, USER_KEY>& p_in) { MAP_TYPE::operator=((MAP_TYPE)p_in); };
|
||
|
|
||
|
// Element functions
|
||
|
const bool add(USER_KEY p_key, USER_DATA& p_in) { return(MAP_TYPE::insert(p_key, p_in)); };
|
||
|
const int add(USER_KEY& p_key[], USER_DATA& p_in[]) { return(MAP_TYPE::insert(p_key, p_in)); };
|
||
|
const bool remove(USER_KEY p_key) { return(MAP_SUBTYPE::remove(p_key)); };
|
||
|
const int remove(USER_KEY& p_key[]) { return(MAP_SUBTYPE::remove(p_key)); };
|
||
|
const bool remove(USER_KEY p_key, USER_DATA& p_removed_data) { return(MAP_TYPE::remove(p_key, p_removed_data)); };
|
||
|
const int remove(USER_KEY& p_key[], USER_DATA& p_removed_data[]) { return(MAP_TYPE::remove(p_key, p_removed_data)); };
|
||
|
|
||
|
USER_DATA minimum() { return(MAP_TYPE::first_element().get_obj()); };
|
||
|
const USER_KEY minimum_key() { return(MAP_TYPE::first_element().get_key()); };
|
||
|
USER_DATA maximum() { return(MAP_TYPE::last_element().get_obj()); };
|
||
|
const USER_KEY maximum_key() { return(MAP_TYPE::last_element().get_key()); };
|
||
|
|
||
|
USER_DATA next_smaller(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::smaller(p_in); if(p_tmp != NULL) { return(p_tmp.get_obj()); } USER_DATA zero; ZeroMemory(zero); return(zero); };
|
||
|
USER_DATA next_greater(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::greater(p_in); if(p_tmp != NULL) { return(p_tmp.get_obj()); } USER_DATA zero; ZeroMemory(zero); return(zero); };
|
||
|
const USER_KEY next_smaller_key(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::smaller(p_in); if(p_tmp != NULL) { return(p_tmp.get_key()); } USER_KEY zero; ZeroMemory(zero); return(zero); };
|
||
|
const USER_KEY next_greater_key(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::greater(p_in); if(p_tmp != NULL) { return(p_tmp.get_key()); } USER_KEY zero; ZeroMemory(zero); return(zero); };
|
||
|
|
||
|
|
||
|
// Comparison operators
|
||
|
const bool operator==(const map<USER_DATA, USER_KEY>& p_in) { return(MAP_TYPE::operator==((MAP_TYPE)p_in)); }
|
||
|
const bool operator!=(const map<USER_DATA, USER_KEY>& p_in) { return(!operator==(p_in)); }
|
||
|
};
|
||
|
|
||
|
#undef NODE_TYPE
|
||
|
#undef MAP_TYPE
|
||
|
|
||
|
|
||
|
|
||
|
// Derived complex type class object for pointers
|
||
|
#define NODE_TYPE object_map_node<USER_DATA, USER_KEY>
|
||
|
#define MAP_TYPE _map<USER_DATA*, USER_KEY, NODE_TYPE>
|
||
|
|
||
|
template <typename USER_DATA, typename USER_KEY>
|
||
|
struct ptr_map : public MAP_TYPE
|
||
|
{
|
||
|
// Constructors / Destructor
|
||
|
ptr_map() : MAP_TYPE() { };
|
||
|
ptr_map(const ptr_map<USER_DATA, USER_KEY>& p_in) : MAP_TYPE(p_in) { };
|
||
|
ptr_map(const bool _do_not_destroy) : MAP_TYPE() { p_params.do_not_destroy = _do_not_destroy; };
|
||
|
~ptr_map() { };
|
||
|
|
||
|
// Assignment operator
|
||
|
void operator=(const ptr_map<USER_DATA, USER_KEY>& p_in) { MAP_TYPE::operator=((MAP_TYPE)p_in); };
|
||
|
|
||
|
// Element functions
|
||
|
const bool add(USER_KEY p_key, USER_DATA& p_in) { USER_DATA* p_tmp = new USER_DATA(p_in); return(MAP_TYPE::insert(p_key, p_tmp)); };
|
||
|
const bool add(USER_KEY p_key, USER_DATA* p_in) { return(MAP_TYPE::insert(p_key, p_in)); };
|
||
|
const int add(USER_KEY& p_key[], USER_DATA& p_in[]) {
|
||
|
USER_DATA* p_tmp[];
|
||
|
for(int cnt = ArrayResize(p_tmp, ArraySize(p_in)); (cnt >= NULL) && !_StopFlag; cnt--)
|
||
|
{ p_tmp[cnt] = new USER_DATA(p_in[cnt]); }
|
||
|
return(MAP_TYPE::insert(p_key, p_tmp));
|
||
|
};
|
||
|
const int add(USER_KEY& p_key[], USER_DATA*& p_in[]) { return(MAP_TYPE::insert(p_key, p_in)); };
|
||
|
const bool remove(USER_KEY p_key, const bool _do_not_destroy = false) { return(MAP_SUBTYPE::remove(p_key, p_params.do_not_destroy || _do_not_destroy)); };
|
||
|
const int remove(USER_KEY& p_key[], const bool _do_not_destroy = false) { return(MAP_SUBTYPE::remove(p_key, p_params.do_not_destroy || _do_not_destroy)); };
|
||
|
const int remove(USER_KEY& p_key[], USER_DATA& p_removed_data[], const bool _do_not_destroy = false) {
|
||
|
USER_DATA* p_tmp[];
|
||
|
if(MAP_TYPE::remove(p_key, p_tmp, true))
|
||
|
{
|
||
|
for(int cnt = ArrayResize(p_removed_data, ArraySize(p_tmp)); (cnt >= NULL) && !_StopFlag; cnt--)
|
||
|
{ p_removed_data[cnt] = p_tmp[cnt]; }
|
||
|
if(!(p_params.do_not_destroy || _do_not_destroy))
|
||
|
{ for(int cnt = ArraySize(p_tmp); (cnt >= NULL) && !_StopFlag; cnt--) { delete(p_tmp[cnt]); } }
|
||
|
return(ArraySize(p_removed_data));
|
||
|
}
|
||
|
return(NULL);
|
||
|
};
|
||
|
const int remove(USER_KEY& p_key[], USER_DATA*& p_removed_data[]) { return(MAP_TYPE::remove(p_key, p_removed_data, true)); };
|
||
|
|
||
|
USER_DATA* minimum() { return(MAP_TYPE::first_element().get_obj()); };
|
||
|
const USER_KEY minimum_key() { return(MAP_TYPE::first_element().get_key()); };
|
||
|
USER_DATA* maximum() { return(MAP_TYPE::last_element().get_obj()); };
|
||
|
const USER_KEY maximum_key() { return(MAP_TYPE::last_element().get_key()); };
|
||
|
|
||
|
USER_DATA* next_smaller(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::smaller(p_in); if(p_tmp != NULL) { return(p_tmp.get_obj()); } USER_DATA zero; ZeroMemory(zero); return(zero); };
|
||
|
USER_DATA* next_greater(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::greater(p_in); if(p_tmp != NULL) { return(p_tmp.get_obj()); } USER_DATA zero; ZeroMemory(zero); return(zero); };
|
||
|
const USER_KEY next_smaller_key(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::smaller(p_in); if(p_tmp != NULL) { return(p_tmp.get_key()); } USER_KEY zero; ZeroMemory(zero); return(zero); };
|
||
|
const USER_KEY next_greater_key(USER_KEY p_in) { NODE_TYPE* p_tmp = MAP_TYPE::greater(p_in); if(p_tmp != NULL) { return(p_tmp.get_key()); } USER_KEY zero; ZeroMemory(zero); return(zero); };
|
||
|
|
||
|
|
||
|
// Comparison operators
|
||
|
const bool operator==(const map<USER_DATA, USER_KEY>& p_in) { return(MAP_TYPE::operator==((MAP_TYPE)p_in)); }
|
||
|
const bool operator!=(const map<USER_DATA, USER_KEY>& p_in) { return(!operator==(p_in)); }
|
||
|
};
|
||
|
|
||
|
#undef NODE_TYPE
|
||
|
#undef MAP_TYPE
|
||
|
#undef MAP_SUBTYPE
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//
|
||
|
// END MQL data structures */
|
||
|
//*********************************************************************************************************************************************************/
|
||
|
#endif // LIB_MQLPLUS_OBJ_MAP_RBTREE_TEMPLATES_MQH_INCLUDED
|