From: umptious@... Date: 2006-12-07T07:00:12+09:00 Subject: YAML problem with cyclic data structures I'm having a problem with YAML in the first slightly-more-than-toy application that I've writing with it. Oddly, when I searched on "ruby yaml cyclic" - the first phrase I thought of to get help - I found that someone had written a program almost exactly like mine a year ago and had the same problem: >>>>>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/150930 I have a program that is trying to use YAML to save out its data, without much success. In the program, several of the classes have cyclic dependancies. To be more specific, the program deals with "rooms" and "connections" between the rooms, with each room and connection being represented as a class. Each room has up to 8 possible connections and each connection contains, in turn, a reference to each of the two rooms it connects. When YAML saves out its data for extremely simple graphs (2 or 3 rooms interconnected), YAML spits out everything fine, and handles the cyclic connections using ids to represent the same objects. Problem seems to be that this is not working appropiately as the graph grows in complexity (even 16 or so rooms can create issues). YAML just hangs when saving out the file or, at least, it takes exponentially much, much, much longer to save the scene (I'm taking minutes vs. less than a second for the 3 rooms). Is this how it should be? It seems like a bug in the YAML library to me. <<<<<<<<<<<<<<<< He (or she) never got an answer. The only things that I can add are: 1. That my Rooms and Doors are "owned" by references from a Floor object and have only WeakRefs to each other 2. Adding a single extra Door can increase YAML's save time from several seconds to longer than the 20 minutes I was willing to wait 3. YAML seems quite happy coping with rooms arranged in a tree structure, but a very few cycle inducing connections - literally 1 to 3 - will drive it crazy. 4. I've looked at my data structures very hard to make sure that they are kosher. Or possibly halal. Comments? I can think of ways around this quite easily for my program, but I'd like to know what YAMLs limitations are, or if I might be doing something wrong. Btw - it seems odd that the Ruby YAML Cookbook doesn't contain the word "cyclic"..