my code is ; $ssf def find_class(class_name, stack = []) FileClass.find(:all, :conditions => ["class_name = ?", class_name]).each do |file_class| FileInclude.find(:all, :conditions => ["file_name = ?", file_class.file_name]).each do |file_include| FileClass.find(:all, :conditions => ["file_name = ?", file_include.file_name]).each do |xxxx| next if stack.include?(xxxx.class_name) begin find_class(file_class.class_name, stack) p file_class p "============================" p file_include p "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------" p xxxx rescue SystemStackError => ssf p $ssf = ssf end end end end end rake aborted! SystemStackError: stack level too deep: SELECT * FROM `file_includes` WHERE (file_name = ''IMAgentHome'') C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'' C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute'' C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:595:in `select'' ..... help me please! -- Posted via http://www.ruby-forum.com/.
On Sep 3, 10:15 am, Ahmet Kilic <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> help me please!Well you seem to be recursing in a pretty uncontrolled way. Fred> -- > Posted viahttp://www.ruby-forum.com/.
You have not mentioned how should recursion stop properly. Anyway, code also doesnt look very clean and I think not very efficient too. My suggestion is first fetch all FileClass using conditions in an array, include all the FileInclude as well (using :include) Then select, reject the record you want to. Sorry, if I haven''t understood your problem correctly. -- Thanks, Abhinav http://twitter.com/abhinav On Thu, Sep 3, 2009 at 2:45 PM, Ahmet Kilic < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > my code is ; > > $ssf > def find_class(class_name, stack = []) > FileClass.find(:all, :conditions => ["class_name = ?", > class_name]).each do |file_class| > FileInclude.find(:all, :conditions => ["file_name = ?", > file_class.file_name]).each do |file_include| > FileClass.find(:all, :conditions => ["file_name = ?", > file_include.file_name]).each do |xxxx| > next if stack.include?(xxxx.class_name) > begin > find_class(file_class.class_name, stack) > > p file_class > p "============================" > p file_include > p "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------" > p xxxx > rescue SystemStackError => ssf > p $ssf = ssf > end > > end > end > end > end > > > rake aborted! > SystemStackError: stack level too deep: SELECT * FROM `file_includes` > WHERE (file_name = ''IMAgentHome'') > > > C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:212:in > `log'' > > C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:320:in > `execute'' > > C:/Base/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:595:in > `select'' > ..... > > > help me please! > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Abhinav Saxena wrote:> You have not mentioned how should recursion stop properly. Anyway, code > also > doesnt look very clean and I think not very efficient too. My suggestion > is > first fetch all FileClass using conditions in an array, include all the > FileInclude as well (using :include) Then select, reject the record you > want > to. > > Sorry, if I haven''t understood your problem correctly. > > -- > Thanks, > Abhinav > http://twitter.com/abhinav > > > > On Thu, Sep 3, 2009 at 2:45 PM, Ahmet Kilic <sorry, my code is not good one, but the code is here, def find_class(class_name, stack = []) puts(("\t" * stack.size) + class_name) # puts(("\t" * stack.size) + "#{class_name}") stack.push class_name FileClass.find(:all, :conditions => ["class_name = ?", class_name]).each do |file_class| FileInclude.find(:all, :conditions => ["file_name = ?", file_class.file_name]).each do |file_include| FileClass.find(:all, :conditions => ["file_name = ?", file_include.file_name]).each do |file_class| next if stack.include?(file_class.class_name) find_class(file_class.class_name, stack) end end end stack.pop end I am testing which part is getting error..> first fetch all FileClass using conditions in an array, include all the > FileInclude as well (using :include) Then select, reject the record you > wantcould you provide a simple example for this(using :include), please! -- Posted via http://www.ruby-forum.com/.
Hi, Can you put in a statement what you are trying to do, probably then I (and others) will be able to help you better. -- Thanks, Abhinav http://twitter.com/abhinav On Thu, Sep 3, 2009 at 3:19 PM, Ahmet Kilic < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Abhinav Saxena wrote: > > You have not mentioned how should recursion stop properly. Anyway, code > > also > > doesnt look very clean and I think not very efficient too. My suggestion > > is > > first fetch all FileClass using conditions in an array, include all the > > FileInclude as well (using :include) Then select, reject the record you > > want > > to. > > > > Sorry, if I haven''t understood your problem correctly. > > > > -- > > Thanks, > > Abhinav > > http://twitter.com/abhinav > > > > > > > > On Thu, Sep 3, 2009 at 2:45 PM, Ahmet Kilic < > > sorry, my code is not good one, but the code is here, > > def find_class(class_name, stack = []) > puts(("\t" * stack.size) + class_name) > # puts(("\t" * stack.size) + "#{class_name}") > stack.push class_name > FileClass.find(:all, :conditions => ["class_name = ?", > class_name]).each do |file_class| > FileInclude.find(:all, :conditions => ["file_name = ?", > file_class.file_name]).each do |file_include| > FileClass.find(:all, :conditions => ["file_name = ?", > file_include.file_name]).each do |file_class| > next if stack.include?(file_class.class_name) > find_class(file_class.class_name, stack) > end > end > end > stack.pop > end > > I am testing which part is getting error.. > > > first fetch all FileClass using conditions in an array, include all the > > FileInclude as well (using :include) Then select, reject the record you > > want > > could you provide a simple example for this(using :include), please! > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Abhinav Saxena wrote:> Hi, > > Can you put in a statement what you are trying to do, probably then I > (and > others) will be able to help you better. > > -- > Thanks, > Abhinav > http://twitter.com/abhinav > > > > On Thu, Sep 3, 2009 at 3:19 PM, Ahmet Kilic <thanks, I improved my code, but still not enough its giving me double result def find_class(class_name, stack = []) puts(("\t" * stack.size) + class_name) stack.push class_name FileClass.find(:all, :conditions => ["class_name = ?", class_name]).each do |file_class| p file_class.file_name + "aaa" FileInclude.find(:all, :conditions => ["file_name = ?", file_class.file_name]).each do |file_include| p file_include.include_file_name + "bbb" FileClass.find(:all, :conditions => ["file_name = ?", file_include.file_name]).each do |file_class| p file_class.class_name + "ccc" next if stack.include?(file_class.class_name) find_class(file_include.include_file_name, stack) end end end stack.pop end --------------------- results --------------------- CTAgentHome "CTAgentHome.haaa" "\"FWCTBase.h\"bbb" "CTAgentHomeRepccc" "FWCTBase.h" "CTAgentHomeccc" "\"FWMOBase.h\"bbb" "CTAgentHomeRepccc" "FWMOBase.h" "CTAgentHomeccc" "\"MOSAgentBasicInfo.h\"bbb" "CTAgentHomeRepccc" "MOSAgentBasicInfo.h" "CTAgentHomeccc" "\"MOSAgentCriteriaInfo.h\"bbb" "CTAgentHomeRepccc" "MOSAgentCriteriaInfo.h" "CTAgentHomeccc" "\"MOSAgentInfo.h\"bbb" "CTAgentHomeRepccc" "MOSAgentInfo.h" "CTAgentHomeccc" "\"MOSAgentMessageInfo.h\"bbb" "CTAgentHomeRepccc" "MOSAgentMessageInfo.h" "CTAgentHomeccc" "CTAgentHomeRep.haaa" "\"FWMOBase.h\"bbb" "CTAgentHomeccc" "CTAgentHomeRepccc" "FWMOBase.h" "\"MOSAgentBasicInfo.h\"bbb" "CTAgentHomeccc" "CTAgentHomeRepccc" "MOSAgentBasicInfo.h" "\"MOSAgentCriteriaInfo.h\"bbb" "CTAgentHomeccc" "CTAgentHomeRepccc" "MOSAgentCriteriaInfo.h" "\"MOSAgentInfo.h\"bbb" "CTAgentHomeccc" "CTAgentHomeRepccc" "MOSAgentInfo.h" "\"MOSAgentMessageInfo.h\"bbb" "CTAgentHomeccc" "CTAgentHomeRepccc" "MOSAgentMessageInfo.h" I made mistake somewhere but where... -- Posted via http://www.ruby-forum.com/.
Help me understand what you are trying to accomplish (please put in words) -- Thanks, Abhinav http://twitter.com/abhinav On Thu, Sep 3, 2009 at 5:06 PM, Ahmet Kilic < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Abhinav Saxena wrote: > > Hi, > > > > Can you put in a statement what you are trying to do, probably then I > > (and > > others) will be able to help you better. > > > > -- > > Thanks, > > Abhinav > > http://twitter.com/abhinav > > > > > > > > On Thu, Sep 3, 2009 at 3:19 PM, Ahmet Kilic < > > > thanks, > I improved my code, but still not enough > its giving me double result > > > def find_class(class_name, stack = []) > puts(("\t" * stack.size) + class_name) > > stack.push class_name > FileClass.find(:all, :conditions => ["class_name = ?", > class_name]).each do |file_class| > p file_class.file_name + "aaa" > FileInclude.find(:all, :conditions => ["file_name = ?", > file_class.file_name]).each do |file_include| > > p file_include.include_file_name + "bbb" > FileClass.find(:all, :conditions => ["file_name = ?", > file_include.file_name]).each do |file_class| > > p file_class.class_name + "ccc" > next if stack.include?(file_class.class_name) > > find_class(file_include.include_file_name, stack) > end > end > end > stack.pop > end > > --------------------- > results > --------------------- > > CTAgentHome > "CTAgentHome.haaa" > "\"FWCTBase.h\"bbb" > "CTAgentHomeRepccc" > "FWCTBase.h" > "CTAgentHomeccc" > "\"FWMOBase.h\"bbb" > "CTAgentHomeRepccc" > "FWMOBase.h" > "CTAgentHomeccc" > "\"MOSAgentBasicInfo.h\"bbb" > "CTAgentHomeRepccc" > "MOSAgentBasicInfo.h" > "CTAgentHomeccc" > "\"MOSAgentCriteriaInfo.h\"bbb" > "CTAgentHomeRepccc" > "MOSAgentCriteriaInfo.h" > "CTAgentHomeccc" > "\"MOSAgentInfo.h\"bbb" > "CTAgentHomeRepccc" > "MOSAgentInfo.h" > "CTAgentHomeccc" > "\"MOSAgentMessageInfo.h\"bbb" > "CTAgentHomeRepccc" > "MOSAgentMessageInfo.h" > "CTAgentHomeccc" > "CTAgentHomeRep.haaa" > "\"FWMOBase.h\"bbb" > "CTAgentHomeccc" > "CTAgentHomeRepccc" > "FWMOBase.h" > "\"MOSAgentBasicInfo.h\"bbb" > "CTAgentHomeccc" > "CTAgentHomeRepccc" > "MOSAgentBasicInfo.h" > "\"MOSAgentCriteriaInfo.h\"bbb" > "CTAgentHomeccc" > "CTAgentHomeRepccc" > "MOSAgentCriteriaInfo.h" > "\"MOSAgentInfo.h\"bbb" > "CTAgentHomeccc" > "CTAgentHomeRepccc" > "MOSAgentInfo.h" > "\"MOSAgentMessageInfo.h\"bbb" > "CTAgentHomeccc" > "CTAgentHomeRepccc" > "MOSAgentMessageInfo.h" > > I made mistake somewhere but where... > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I am trying to recursive call. An the resut should be like this resullts ------------ CTAgentHome FWCTBase.h FWMOBase.h MOSAgentBasicInfo.h MOSAgentMessageInfo.h I am tring to find CTAgentHome''s include classes. I think it is clear now. On Sep 3, 10:23 pm, Abhinav Saxena <abhinav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Help me understand what you are trying to accomplish (please put in words) > -- > Thanks, > Abhinavhttp://twitter.com/abhinav > > On Thu, Sep 3, 2009 at 5:06 PM, Ahmet Kilic < > > rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Abhinav Saxena wrote: > > > Hi, > > > > Can you put in a statement what you are trying to do, probably then I > > > (and > > > others) will be able to help you better. > > > > -- > > > Thanks, > > > Abhinav > > >http://twitter.com/abhinav > > > > On Thu, Sep 3, 2009 at 3:19 PM, Ahmet Kilic < > > > thanks, > > I improved my code, but still not enough > > its giving me double result > > > def find_class(class_name, stack = []) > > puts(("\t" * stack.size) + class_name) > > > stack.push class_name > > FileClass.find(:all, :conditions => ["class_name = ?", > > class_name]).each do |file_class| > > p file_class.file_name + "aaa" > > FileInclude.find(:all, :conditions => ["file_name = ?", > > file_class.file_name]).each do |file_include| > > > p file_include.include_file_name + "bbb" > > FileClass.find(:all, :conditions => ["file_name = ?", > > file_include.file_name]).each do |file_class| > > > p file_class.class_name + "ccc" > > next if stack.include?(file_class.class_name) > > > find_class(file_include.include_file_name, stack) > > end > > end > > end > > stack.pop > > end > > > --------------------- > > results > > --------------------- > > > CTAgentHome > > "CTAgentHome.haaa" > > "\"FWCTBase.h\"bbb" > > "CTAgentHomeRepccc" > > "FWCTBase.h" > > "CTAgentHomeccc" > > "\"FWMOBase.h\"bbb" > > "CTAgentHomeRepccc" > > "FWMOBase.h" > > "CTAgentHomeccc" > > "\"MOSAgentBasicInfo.h\"bbb" > > "CTAgentHomeRepccc" > > "MOSAgentBasicInfo.h" > > "CTAgentHomeccc" > > "\"MOSAgentCriteriaInfo.h\"bbb" > > "CTAgentHomeRepccc" > > "MOSAgentCriteriaInfo.h" > > "CTAgentHomeccc" > > "\"MOSAgentInfo.h\"bbb" > > "CTAgentHomeRepccc" > > "MOSAgentInfo.h" > > "CTAgentHomeccc" > > "\"MOSAgentMessageInfo.h\"bbb" > > "CTAgentHomeRepccc" > > "MOSAgentMessageInfo.h" > > "CTAgentHomeccc" > > "CTAgentHomeRep.haaa" > > "\"FWMOBase.h\"bbb" > > "CTAgentHomeccc" > > "CTAgentHomeRepccc" > > "FWMOBase.h" > > "\"MOSAgentBasicInfo.h\"bbb" > > "CTAgentHomeccc" > > "CTAgentHomeRepccc" > > "MOSAgentBasicInfo.h" > > "\"MOSAgentCriteriaInfo.h\"bbb" > > "CTAgentHomeccc" > > "CTAgentHomeRepccc" > > "MOSAgentCriteriaInfo.h" > > "\"MOSAgentInfo.h\"bbb" > > "CTAgentHomeccc" > > "CTAgentHomeRepccc" > > "MOSAgentInfo.h" > > "\"MOSAgentMessageInfo.h\"bbb" > > "CTAgentHomeccc" > > "CTAgentHomeRepccc" > > "MOSAgentMessageInfo.h" > > > I made mistake somewhere but where... > > -- > > Posted viahttp://www.ruby-forum.com/.
I think the problem is you are using the wrong algorithm to solve your problem. DFS (depth-first-search) algorithms will easily repeat sequences across subtrees. Starting at CTAgentHome: CTAgentHome.h and CTAgentHomeRep.h both share the same [FWMOBase.h, MOSAgentBasicInfo.h, MOSAgentCriteriaInfo.h, MOSAgentInfo.hMOSAgentMessageInfo.h] subtrees. By the time you''re back processing CTAgentHomeRep.h at level aaa, none of those class_name''s previously seen exist on the stack anymore, so the new recursive path doesn''t know that they''ve already been logged. Or I really don''t grok your code, and I haven''t had nearly enough coffee today. -- Posted via http://www.ruby-forum.com/.