Skip to main content
Code Review

Timeline for Swiftly counting rooms in a floor plan

Current License: CC BY-SA 4.0

7 events
when toggle format what by license comment
Jul 23, 2018 at 19:13 vote accept Martin R
Jul 23, 2018 at 16:22 comment added Martin R @CrisLuengo: Yes, UnionFind() returns a "reference" to a newly allocated object. Swift has "automatic reference counting," which essentially means that the compiler generates to code to increase and decrease reference counts as appropriate. So you can pass references around, copy them etc. The object is deallocated when no reference exists anymore. – Implementing the tree as (automatically memory managed ) "nodes" with pointers to the parent was convenient and is my first approach to this topic. I'll try your suggestion when I find the time.
Jul 23, 2018 at 15:47 comment added Cris Luengo A question about the code: Does tracker[offset] = UnionFind() allocate a new bit of memory to store the object? I presume so, and I presume that var parent: UnionFind? is a reference of sorts, otherwise the algorithm wouldn't work. If this is the case, it would be more efficient (presumably) to keep an array of UnionFind elements, and refer to them by their index instead.
Jul 23, 2018 at 6:04 history tweeted twitter.com/StackCodeReview/status/1021274891427905536
Jul 23, 2018 at 5:25 history edited Martin R CC BY-SA 4.0
Added test case from https://codereview.stackexchange.com/a/200070/35991. The code is not modified, the answer is not invalidated.
Jul 22, 2018 at 23:20 answer added Cris Luengo timeline score: 4
Jul 22, 2018 at 22:16 history asked Martin R CC BY-SA 4.0

AltStyle によって変換されたページ (->オリジナル) /