//+------------------------------------------------------------------+ //| DuplicateFinder.mqh | //| Copyright 2026, MasterOfPuppets | //| https://forge.mql5.io/masterofpuppets/mql5 | //+------------------------------------------------------------------+ #ifndef MASTER_OF_PUPPETS_LIB_DUPLICATE_FINDER_MQH #define MASTER_OF_PUPPETS_LIB_DUPLICATE_FINDER_MQH #property copyright "Copyright 2026, MasterOfPuppets" #property link "https://forge.mql5.io/masterofpuppets/mql5" //+------------------------------------------------------------------+ //| Structs | //+------------------------------------------------------------------+ template struct DuplicateResult { T value; uint indices[]; }; //+------------------------------------------------------------------+ //| Duplicate finder class | //+------------------------------------------------------------------+ template class DuplicateFinder { public: static void Find(const T &source[], DuplicateResult &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 //+------------------------------------------------------------------+