From 42da1b94733b84d4d4da53690893fa2193a342c7 Mon Sep 17 00:00:00 2001 From: lfainsin Date: Thu, 24 Dec 2020 18:22:52 +0000 Subject: [PATCH] ajout rapide de is_sorted_and_uniq git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@210410 e13453a9-b01f-0410-a051-f404c4f0c485 --- Makefile | 1 + README.md | 6 ++++-- src/pagerank.adb | 15 ++++++++++++--- src/vector.adb | 15 +++++++++++++++ src/vector.ads | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 54178f5..85cdff3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ make: + make clean && \ cd build/ && \ gnat make -gnatwa -gnata -g ../src/*.adb diff --git a/README.md b/README.md index b2d65d8..4845b8d 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,11 @@ $ make test - sortir quicksort et en faire un module générique - procédure pour compter les doublons dans le réseau - robustesse doublon args - +- revoir l'algo de tri, trier que la première colonne +- faire en sorte de détecter les dupes dans al seconde colonne non triées. +- faire des sous-lib Google https://www.youtube.com/watch?v=JCdgUrTVbLc # question à poser worm precision 10 broken -brainlinks.ord broken décalage de 1, pas de page 0 \ No newline at end of file +brainlinks.ord broken décalage de 1, pas de page 0 diff --git a/src/pagerank.adb b/src/pagerank.adb index 484d386..c6f20f5 100644 --- a/src/pagerank.adb +++ b/src/pagerank.adb @@ -183,6 +183,8 @@ begin network: Vector_Link.T_Vecteur; row, col: Natural; + + sorted: Boolean; dupe: Natural; pi: Vector_Double.T_Vecteur; @@ -200,9 +202,16 @@ begin put_line("loaded in memory the network"); -- on trie le réseau, si besoin - if not naif then -- and then not(is_sorted(network)) then - quicksort(network); - put_line("sorted the network"); + is_sorted_and_uniq(network, dupe, sorted); + if not naif then + if not sorted then + put_line("network is not sorted"); + quicksort(network); + put_line("sorted the network"); + end if; + if dupe > 0 then + put_line("deleted the duplicates ####### TODO #######"); + end if; end if; -- on compte le nombre de doublons diff --git a/src/vector.adb b/src/vector.adb index 199cc4c..fb82911 100644 --- a/src/vector.adb +++ b/src/vector.adb @@ -245,6 +245,21 @@ package body Vector is end loop; end put; + procedure is_sorted_and_uniq(vec: in T_Vecteur; dupe: out Natural; sorted: out Boolean) is + last: T_Link := vec(0); + begin + sorted := True; + dupe := 0; + for i in 1..Capacite-1 loop + if vec(i) < last then + sorted := False; + elsif vec(i) = last then + dupe := dupe + 1; + end if; + last := vec(i); + end loop; + end is_sorted_and_uniq; + function "<"(left, right: in T_Link) return Boolean is begin if left.from < right.from then diff --git a/src/vector.ads b/src/vector.ads index df9ccbe..15de0ac 100644 --- a/src/vector.ads +++ b/src/vector.ads @@ -71,8 +71,8 @@ package Vector is procedure put(vec: in T_Vecteur); + procedure is_sorted_and_uniq(vec: in T_Vecteur; dupe: out Natural; sorted: out Boolean); function "<"(left, right: in T_Link) return Boolean; - procedure quicksort(vec: in out T_Vecteur; low: Natural := 0; high: Natural := Capacite-1); end Link;