* [sup-devel] [PATCH] Avoid O(n^2) complexity for maildir deduplication.
@ 2011-01-20 22:44 Edward Z. Yang
2011-03-13 16:42 ` Damien Leone
0 siblings, 1 reply; 3+ messages in thread
From: Edward Z. Yang @ 2011-01-20 22:44 UTC (permalink / raw)
To: sup-devel, ezyang
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
---
lib/sup/maildir.rb | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
index ba8efed..bc30baa 100644
--- a/lib/sup/maildir.rb
+++ b/lib/sup/maildir.rb
@@ -128,14 +128,16 @@ class Maildir < Source
## deleted arrays, meaning that its flags changed or that it has
## been moved, these ids need to be removed from added and deleted
add_to_delete = del_to_delete = []
+ map = Hash.new { |hash, key| hash[key] = [] }
+ deleted.each do |id_del|
+ map[maildir_data(id_del)[0]].push id_del
+ end
added.each do |id_add|
- deleted.each do |id_del|
- if maildir_data(id_add)[0] == maildir_data(id_del)[0]
+ map[maildir_data(id_add)[0]].each do |id_del|
updated.push [ id_del, id_add ]
add_to_delete.push id_add
del_to_delete.push id_del
end
- end
end
added -= add_to_delete
deleted -= del_to_delete
--
1.7.0.4
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-devel] [PATCH] Avoid O(n^2) complexity for maildir deduplication.
2011-01-20 22:44 [sup-devel] [PATCH] Avoid O(n^2) complexity for maildir deduplication Edward Z. Yang
@ 2011-03-13 16:42 ` Damien Leone
0 siblings, 0 replies; 3+ messages in thread
From: Damien Leone @ 2011-03-13 16:42 UTC (permalink / raw)
To: sup-devel
Pushed, thanks!
Excerpts from Edward Z. Yang's message of jeu. janv. 20 23:44:13 +0100 2011:
> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
> ---
> lib/sup/maildir.rb | 8 +++++---
> 1 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
> index ba8efed..bc30baa 100644
> --- a/lib/sup/maildir.rb
> +++ b/lib/sup/maildir.rb
> @@ -128,14 +128,16 @@ class Maildir < Source
> ## deleted arrays, meaning that its flags changed or that it has
> ## been moved, these ids need to be removed from added and deleted
> add_to_delete = del_to_delete = []
> + map = Hash.new { |hash, key| hash[key] = [] }
> + deleted.each do |id_del|
> + map[maildir_data(id_del)[0]].push id_del
> + end
> added.each do |id_add|
> - deleted.each do |id_del|
> - if maildir_data(id_add)[0] == maildir_data(id_del)[0]
> + map[maildir_data(id_add)[0]].each do |id_del|
> updated.push [ id_del, id_add ]
> add_to_delete.push id_add
> del_to_delete.push id_del
> end
> - end
> end
> added -= add_to_delete
> deleted -= del_to_delete
--
Damien Leone <damien.leone@fensalir.fr>
Web: http://dleone.fensalir.fr/
GPG: 0x82EB4DDF
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [sup-devel] [PATCH] Avoid O(n^2) complexity for maildir deduplication.
@ 2011-01-20 2:44 Edward Z. Yang
0 siblings, 0 replies; 3+ messages in thread
From: Edward Z. Yang @ 2011-01-20 2:44 UTC (permalink / raw)
To: sup-devel, ezyang
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
---
lib/sup/maildir.rb | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
index ba8efed..0898c91 100644
--- a/lib/sup/maildir.rb
+++ b/lib/sup/maildir.rb
@@ -128,14 +128,17 @@ class Maildir < Source
## deleted arrays, meaning that its flags changed or that it has
## been moved, these ids need to be removed from added and deleted
add_to_delete = del_to_delete = []
+ map = {}
added.each do |id_add|
- deleted.each do |id_del|
- if maildir_data(id_add)[0] == maildir_data(id_del)[0]
+ map[maildir_data(id_add)[0]] = id_add
+ end
+ deleted.each do |id_del|
+ id_add = maildir_data(id_del)[0]
+ if not id_add.nil?
updated.push [ id_del, id_add ]
add_to_delete.push id_add
del_to_delete.push id_del
end
- end
end
added -= add_to_delete
deleted -= del_to_delete
--
1.7.0.4
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-13 17:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-20 22:44 [sup-devel] [PATCH] Avoid O(n^2) complexity for maildir deduplication Edward Z. Yang
2011-03-13 16:42 ` Damien Leone
-- strict thread matches above, loose matches on Subject: below --
2011-01-20 2:44 Edward Z. Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox