cyclic

checking whether mutable list has cycle in ocaml?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 17:32:11
问题 I'm trying to write a function to test whether a mutable list in Ocaml contains a cycle or not (that is, has a reference to itself and repeats continuously. My list is defined as type 'a m_list = Nil | Cons of 'a * (('a m_list) ref) . So far, I have: let is_cyclic list = let rec check xs = match (!xs) with |Nil -> false |Cons(_,v) -> ((!v)==list)||check v in match list with |Nil -> false |Cons(_, x) -> check x ;; but it's not quite right and I'm unsure how to proceed from here...thanks for

How does one avoid a cyclic redirect when writing a facebook application using pyfacebook and google app engine?

百般思念 提交于 2019-12-08 03:02:09
问题 I'm trying to write my first application for Facebook using python and pyfacebook hosted on Google App Engine. The problem I'm facing is that of cyclic redirects. Firefox dies complaining "This page isn't redirecting properly" when I visit http://apps.facebook.com/appname. Here's the code: class CanvasHandler(webapp.RequestHandler): def get(self): ## instantiate the Facebook API wrapper with your FB App's keys fb = facebook.Facebook(config.FACEBOOK_API_KEY, config.FACEBOOK_API_SECRET) ##

Serialize cyclic object tree – StackOverflowError – custom serialization code needed

爷,独闯天下 提交于 2019-12-08 00:23:42
问题 I am making an android app where I have a bidirectional cyclic object tree that I need to serialize to fill in a blob field in a Sqlite database. But the default serialization implementation throws a StackOverflowError at me (stack trace at the bottom). But I have no experience in writing custom java serialization code to avoid this situation. I this thread( StackOverflowError when serializing an object in Java ) he talks about the issue, but how to implement it in my case I haven’t really

How to override println behavior for reference types

跟風遠走 提交于 2019-12-07 05:34:23
问题 I have a cyclic graph I created using dosync and ref-set . When I pass this to println I get a java.lang.StackOverflowError as I would expect, because it's effectively trying to print an infinitely-nested structure. I found that if I do (str my-ref) it creates something that looks like vertex@23f7d873 and doesn't actually try to traverse the structure and print everything out, so this solves the problem in the immediate sense, but only helps when I'm very careful about what I'm printing to

C# : xml serialization of nodes with cyclic links

大城市里の小女人 提交于 2019-12-07 04:00:43
问题 I have a class Node something like this : class Node { IEnumerable<Node> inputs; } Which basicly defines a simple graph. I want to serialize my graph to a human-readable form, so normally I'd say xml would be the way to go. But XML wasn't made with cyclic dependencies in mind :) So - what would be the best way to go for serialization of my graph ? I can think of a few ways : ditch XML, create my own format. use XML, tag each node with a unique ID, store connection-lists separate from the

Serialize cyclic object tree – StackOverflowError – custom serialization code needed

偶尔善良 提交于 2019-12-06 14:14:31
I am making an android app where I have a bidirectional cyclic object tree that I need to serialize to fill in a blob field in a Sqlite database. But the default serialization implementation throws a StackOverflowError at me (stack trace at the bottom). But I have no experience in writing custom java serialization code to avoid this situation. I this thread( StackOverflowError when serializing an object in Java ) he talks about the issue, but how to implement it in my case I haven’t really any idea: It's possible to define a writeObject() method for such a list class that, when the first link

Is backtracking absolutely necessary for cycle detection using DFS in directed graph?

[亡魂溺海] 提交于 2019-12-06 11:26:22
I came across this SO post where it is suggested that cycle detection using DFS in a directed graph is faster because of backtracking. Here I quote from that link: Depth first search is more memory efficient than breadth first search as you can backtrack sooner. It is also easier to implement if you use the call stack but this relies on the longest path not overflowing the stack. Also if your graph is directed then you have to not just remember if you have visited a node or not, but also how you got there. Otherwise you might think you have found a cycle but in reality all you have is two

How does one avoid a cyclic redirect when writing a facebook application using pyfacebook and google app engine?

那年仲夏 提交于 2019-12-06 11:20:58
I'm trying to write my first application for Facebook using python and pyfacebook hosted on Google App Engine. The problem I'm facing is that of cyclic redirects. Firefox dies complaining "This page isn't redirecting properly" when I visit http://apps.facebook.com/appname . Here's the code: class CanvasHandler(webapp.RequestHandler): def get(self): ## instantiate the Facebook API wrapper with your FB App's keys fb = facebook.Facebook(config.FACEBOOK_API_KEY, config.FACEBOOK_API_SECRET) ## check that the user is logged into FB and has added the app ## otherwise redirect to where the user can

How to override println behavior for reference types

佐手、 提交于 2019-12-05 09:38:19
I have a cyclic graph I created using dosync and ref-set . When I pass this to println I get a java.lang.StackOverflowError as I would expect, because it's effectively trying to print an infinitely-nested structure. I found that if I do (str my-ref) it creates something that looks like vertex@23f7d873 and doesn't actually try to traverse the structure and print everything out, so this solves the problem in the immediate sense, but only helps when I'm very careful about what I'm printing to the screen. I'd like to be able to call (println my-graph) have it print the ref as some type of custom

The Elegant way to handle Cyclic Event in Java?

≯℡__Kan透↙ 提交于 2019-12-05 07:49:11
i think this not a specific problem to me; everybody might have encountered this issue before. To properly illustrate it, here's a simple UI: As you can see, those two spinners are controlling a single variable -- "A". The only difference is that they control it using different views. Since these two spinners' displaying values are synchronized, cyclic event shows up. If i change the top spinner, "A" will be changed and the bottom spinner's value will also be updated accordingly. However , updating the bottom spinner's call (such as setValue) will also trigger another event instructing the top