120 lines
6.6 KiB
MQL5
120 lines
6.6 KiB
MQL5
|
#ifndef LIB_MQLPLUS_OBJ_RBTREE_TEMPLATES_MQH_INCLUDED
|
||
|
#define LIB_MQLPLUS_OBJ_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_tree_rb.mqh"
|
||
|
#include "base/lib_base_tree.mqh"
|
||
|
|
||
|
|
||
|
|
||
|
/*********************************************************************************************************************************************************/
|
||
|
/* */
|
||
|
/* MQLplus data structures */
|
||
|
/* */
|
||
|
/*********************************************************************************************************************************************************/
|
||
|
|
||
|
|
||
|
///////////////////////////////////////
|
||
|
//
|
||
|
// Red Black Tree object
|
||
|
//
|
||
|
|
||
|
// Derived simple type class object
|
||
|
#define RBTREE_NODE_TYPE object_rb_tree_node<USER_DATA>
|
||
|
#define TREE_TYPE _tree<USER_DATA, RBTREE_NODE_TYPE>
|
||
|
|
||
|
template <typename USER_DATA>
|
||
|
struct redblack_tree : public TREE_TYPE
|
||
|
{
|
||
|
public:
|
||
|
// Constructors / Destructor
|
||
|
redblack_tree() : TREE_TYPE() { };
|
||
|
redblack_tree(const redblack_tree<USER_DATA>& p_in) : TREE_TYPE(p_in) { };
|
||
|
~redblack_tree() { };
|
||
|
|
||
|
// Assignment operator
|
||
|
void operator=(const redblack_tree<USER_DATA>& p_in) { TREE_TYPE::operator=((TREE_TYPE)p_in); };
|
||
|
|
||
|
// Element functions
|
||
|
const bool add(USER_DATA& p_in) { return(TREE_TYPE::insert(p_in)); };
|
||
|
const bool remove(USER_DATA& p_in) { return(TREE_TYPE::remove(p_in)); };
|
||
|
|
||
|
// Comparison operators
|
||
|
const bool operator==(const redblack_tree<USER_DATA>& p_in) { return(TREE_TYPE::operator==((TREE_TYPE)p_in)); }
|
||
|
const bool operator!=(const redblack_tree<USER_DATA>& p_in) { return(!operator==(p_in)); }
|
||
|
};
|
||
|
|
||
|
#undef TREE_TYPE
|
||
|
#undef RBTREE_NODE_TYPE
|
||
|
|
||
|
|
||
|
|
||
|
// Derived complex type class object for pointers
|
||
|
#define RBTREE_NODE_TYPE ptr_object_rb_tree_node<USER_DATA>
|
||
|
#define TREE_TYPE _tree<USER_DATA*, RBTREE_NODE_TYPE>
|
||
|
|
||
|
template <typename USER_DATA>
|
||
|
struct ptr_redblack_tree : public TREE_TYPE
|
||
|
{
|
||
|
public:
|
||
|
// Constructors / Destructor
|
||
|
ptr_redblack_tree() : TREE_TYPE() { };
|
||
|
ptr_redblack_tree(const ptr_redblack_tree<USER_DATA>& p_in) : TREE_TYPE(p_in) { };
|
||
|
ptr_redblack_tree(const bool _do_not_destroy) : _tree() { p_params.do_not_destroy = _do_not_destroy; };
|
||
|
~ptr_redblack_tree() { };
|
||
|
|
||
|
// Assignment operator
|
||
|
void operator=(const ptr_redblack_tree<USER_DATA>& p_in) { TREE_TYPE::operator=((TREE_TYPE)p_in); };
|
||
|
|
||
|
// Buffer functions
|
||
|
bool dnd(const bool _do_not_destroy = true) { p_params.do_not_destroy |= _do_not_destroy; return(p_params.do_not_destroy); };
|
||
|
|
||
|
// Element functions
|
||
|
const bool add(USER_DATA& p_in) { USER_DATA* tmp_ptr = new USER_DATA(p_in); return(TREE_TYPE::insert(tmp_ptr)); };
|
||
|
const bool add(USER_DATA* p_in) { return(TREE_TYPE::insert(p_in)); };
|
||
|
|
||
|
const bool remove(USER_DATA& p_in, const bool _do_not_destroy = false) { USER_DATA* tmp_ptr = GetPointer(p_in); return(TREE_TYPE::remove(tmp_ptr, p_params.do_not_destroy || _do_not_destroy)); };
|
||
|
const bool remove(USER_DATA* p_in, const bool _do_not_destroy = false) { return(TREE_TYPE::remove(p_in, p_params.do_not_destroy || _do_not_destroy)); };
|
||
|
|
||
|
// Comparison operators
|
||
|
const bool operator==(const ptr_redblack_tree<USER_DATA>& p_in) { return(TREE_TYPE::operator==((TREE_TYPE)p_in)); }
|
||
|
const bool operator!=(const ptr_redblack_tree<USER_DATA>& p_in) { return(!operator==(p_in)); }
|
||
|
};
|
||
|
|
||
|
#undef TREE_TYPE
|
||
|
#undef RBTREE_NODE_TYPE
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//
|
||
|
// END MQL data structures */
|
||
|
//*********************************************************************************************************************************************************/
|
||
|
#endif // LIB_MQLPLUS_OBJ_RBTREE_TEMPLATES_MQH_INCLUDED
|