2026-03-03 01:24:43 +03:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| DuplicateFinder.mqh |
|
|
|
|
|
//| Copyright 2026, MasterOfPuppets |
|
|
|
|
|
//| https://forge.mql5.io/masterofpuppets/mql5 |
|
|
|
|
|
//+------------------------------------------------------------------+
|
2026-03-03 01:41:15 +03:00
|
|
|
#ifndef MASTER_OF_PUPPETS_LIB_DUPLICATE_FINDER_MQH
|
|
|
|
|
#define MASTER_OF_PUPPETS_LIB_DUPLICATE_FINDER_MQH
|
2026-03-03 01:24:43 +03:00
|
|
|
|
|
|
|
|
#property copyright "Copyright 2026, MasterOfPuppets"
|
|
|
|
|
#property link "https://forge.mql5.io/masterofpuppets/mql5"
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Structs |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct DuplicateResult
|
|
|
|
|
{
|
|
|
|
|
T value;
|
|
|
|
|
uint indices[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Duplicate finder class |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
template<typename T>
|
|
|
|
|
class DuplicateFinder
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static void Find(const T &source[], DuplicateResult<T> &duplicateResults[])
|
|
|
|
|
{
|
|
|
|
|
ArrayFree(duplicateResults);
|
|
|
|
|
int sourceSize = ArraySize(source);
|
|
|
|
|
if(sourceSize <= 1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bool processed[];
|
|
|
|
|
ArrayResize(processed, sourceSize);
|
|
|
|
|
ArrayInitialize(processed, false);
|
|
|
|
|
for(int i = 0; i < sourceSize; i++)
|
|
|
|
|
{
|
|
|
|
|
if(processed[i])
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
int foundCount = 0;
|
|
|
|
|
int tempIndices[];
|
|
|
|
|
for(int j = i; j < sourceSize; j++)
|
|
|
|
|
{
|
|
|
|
|
if(source[i] == source[j])
|
|
|
|
|
{
|
|
|
|
|
ArrayResize(tempIndices, foundCount + 1);
|
|
|
|
|
tempIndices[foundCount] = j;
|
|
|
|
|
foundCount++;
|
|
|
|
|
if(j != i)
|
|
|
|
|
{
|
|
|
|
|
processed[j] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(foundCount > 1)
|
|
|
|
|
{
|
|
|
|
|
int resIdx = ArraySize(duplicateResults);
|
|
|
|
|
ArrayResize(duplicateResults, resIdx + 1);
|
|
|
|
|
duplicateResults[resIdx].value = source[i];
|
|
|
|
|
ArrayCopy(duplicateResults[resIdx].indices, tempIndices);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
//+------------------------------------------------------------------+
|