Giter VIP home page Giter VIP logo

animan01 / chain-of-duplicates-in-a-csv-union-find-php Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 25 KB

Union find PHP. This realization union find algorithm is a tool for searching chains of duplicates in CSV file (php). The solution can be an example of Union find implementation in PHP.

License: GNU General Public License v3.0

PHP 100.00%
php algorithm duplicates csv relations parsing union-find union-find-algorithm example php-union-find

chain-of-duplicates-in-a-csv-union-find-php's Introduction

Alhoritm

Disjoint-set/Union-find Forest

Problem/Motivation

Find duplicates in CSV file. The problem was the related search for duplicates in the data table. On demand there is a need to find a duplicate from key fields (in any field) and to assign the first duplicate occurrence to PARENT_ID.

Union find algorithm implemented on PHP, finding a chain of duplicates and generates result with ID and PARENT_ID was created.

Since there were no similar implementations of Union find algorithm, it was decided to write it yourself on PHP.

Example of input data (based on the csv file):

ID,PARENT_ID,EMAIL,CARD,PHONE,TMP
1,NULL,email1,card1,phone1,
2,NULL,email2,card1,phone2,
3,NULL,email3,card3,phone3,
4,NULL,email1,card2,phone4,
5,NULL,email5,card5,phone2,
6,NULL,email6,card6,phone6,
7,NULL,email3,card9,phone7,
8,NULL,email8,card10,phone8,
9,NULL,email9,card9,phone3,
10,NULL,email2,card10,phone10,

In the example of the element with ID 10 it was associated with 2,8,4,1. Original duplicate 1. Brief visualization of dependencies:

  • ID1 => ID2 => ID10 => ID8

Require

  • php

How to run it?

Run on console: php index.php or open in browser.

Demo results

ID,PARENT_ID
1,1
2,1
3,3
4,1
5,1
6,6
7,3
8,1
9,3
10,1

PS. You can check results on: http://sandbox.onlinephpfunctions.com/

chain-of-duplicates-in-a-csv-union-find-php's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.