Grasshopper

algorithmic modeling for Rhino

# Lists, Sets, Strings & Trees

Can someone please direct or tell me the differences between these different data management systems... I understand the basic concept of the branch data, but don't really understand how to use the sets and strings... please help... Thanks

Views: 33713

### Replies to This Discussion

• Lists. A List is an ordered (but not necessarily sorted) collection of data. Lists may contain zero elements, a single element, or (at most) 2,147,483,647 elements. Furthermore, the same element can occur more than once in the same list, and different elements with identical values can occur more than once. Also, a list may contain lack of elements, referred to as "nulls".
• Sets. Strictly speaking a Set is a mathematical construct which adheres to a strict collection of rules and limitations. Basically, a Set is the same as a List, with the exception that it cannot contain the same element more than once, or indeed two or more different elements with the same values. You see, in mathematics there is no difference between a value and an instance of that value, they are the same thing. In programming however it is possible to store the number 7 in more than one spot in the RAM. Grasshopper does not enforce this rule very strongly though, you can use a lot of Set components on lists that have multiple occurrences of the same value. The big difference between Lists and Sets in Grasshopper is that Sets are only defined for simple data types that have trivial equality comparisons. Basically: booleans, integers, numbers, complex numbers, strings, points, vectors, colours and intervals. Lists can contain all kinds of data.
• Strings. Strings are text. There's nothing more to it. I don't know why early programmers chose to call them strings, but I suppose it's a better description of the memory representation of them. Strings are essentially sequences of individual characters.
• Trees. Trees are the way all data is stored in Grasshopper. Even when you only have a single item, it will still be stored in a tree. A tree is a sorted collection of lists, where each list is identified by a path. A specific path can only occur once in a tree, when you merge two trees together, lists with identical paths are appended to each other. Trees are an attempt to losslessly represent not just the data itself, but also the history of that data. Imagine you have 4 curves {A,B,C,D} and you divide each into 3 points {X,Y,Z}. Then, for each of those points you create a new line segment {X',Y',Z'} and then divide each of those line segments again into 5 points each {K,L,M,N,O}. The way data is stored in trees, it should be possible to figure out whether a point M belongs to X' or to Z', and whether that X' or Z' came from A, B, C or D. This is why paths are often quite long after a while, because they encode a lot of history.
• Paths. A Path is nothing more than a list of integers. It's denoted using curly brackets and semi-colons: {A;B;...;Z}. A Path should never be empty {} or have negative integers {0;-1}, but it is certainly possible to create a path like this and it probably won't even crash Grasshopper. Paths are 'grown' by components that (potentially) create more than one output value for a single input value. For example Divide Curve. It creates N points for every single input curve. In cases like this a new integer is appended to the end of the path.

In the next release the Path logic in Grasshopper is somewhat different. I fixed a number of obscure bugs (hopefully without introducing new fresh bugs) and special cased certain operations to somewhat reduce the speed at which paths grow. This may well break files that rely on a specific tree layout, but I hope the temporary sacrifice will be worth the long-term benefits.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

David... Thanks so much for the quick reply, I'm sure your a busy person! This deff helps out a lot understanding the differences and how they are used.... but to clarify a bit

1) If a List can contain everything that a Set can what is the benefit from using the Set?

2) As Strings are simple text, is this just as simple as it sounds or is/can it be representational?  Ex. A=5 or A=(5,3,9) like in mathematics and programming

Lastly, 3) Can List components be used to control branches or just the specific items in the whole list?  I have a group of data (from the SBox component) that I divided, using the subset length n component from Pieter http://www.grasshopper3d.com/xn/detail/2985220:Comment:444534, into separate branches and I am trying to use the Cull Pattern component to cull the different branches to apply a different geometry to this new group(list?) of data.... I have attached the files and a screenshot.

As always, thank you so much for your help!!!

1) If a List can contain everything that a Set can what is the benefit from using the Set?

There is no benefit. Which is why Sets aren't actually a type of storage in Grasshopper. It's just that some components internally treat Lists as Sets. These components look at the value of the items in the Set rather than their position in memory. This is why the [Item Index] component works differently from the [Member Index] component. Both do something useful although you almost always need [Member Index].

2) As Strings are simple text, is this just as simple as it sounds or is/can it be representational?  Ex. A=5 or A=(5,3,9) like in mathematics and programming

I don't quite follow. Strings are text. There is no meaning to them beyond that. However some components/parameter may choose to interpret strings. For example if you plug a string with value "0.5 * Pi" into a number parameter, it will attempt to evaluate that expression as a number and it will adopt the number value 1.5707963267948966192313216916398. If you plug a string that does not evaluate to a number into a number parameter you will get a conversion error.

3) Can List components be used to control branches or just the specific items in the whole list?

Define "List components". Are you talking about all the components inside the Sets→List panel? If so, then no. Components in the List panel do not really give access to the path bit of trees. For that you need components from the Sets→Tree panel.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I guess what I was getting at with

2) is how can a String obtain the value "0.5 * Pi" if it only contains text?

3) Yes that is exactly what I was asking.. Great this is helps!! But now the question would be which components from the Tree panel should I be looking to use to retrieve a cull pattern of branches from the tree?  Ex. I have a list of 17 branches with 8 items in each and I want to only access every other branch. Such as a "true, false" cull pattern.

Thanks again

Hi Jason,

I demonstrated a cull Nth Nth approach in this discussion http://www.grasshopper3d.com/forum/topics/2nd-item-from-every-2nd-r...

which sounds similar to your needs

A string can contain any collection of characters. "0.5 * Pi" is just one of these possible collections. So is "0;5 * Pi", which is a valid string but cannot be evaluated to a number. "0.5 * iP" is another valid string that does not evaluate to a number.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Danny, thanks... that helped a bunch.

David, I also realized that I was confusing the "cull" components as being in the List pulldown menu, so that is probably where the confusion on my part was... also, thank you for the help with understanding strings... again I had a confusion here thinking "text" meant "alphabet".... been a long day, sorry

Thanks again for the help guys

can we copy this to the FAQ's

I'm guessing this is directed toward David... I think it would be great to put it in FAQ's as that is where I looked first to find the answer, but I don't know how I would be able to put it there.

Hi,

I'm pretty new to Grasshopper and i'm using it for a unit of my Masters.

The problem is:

I have 2 sets of curve(polygon) data. Set 1 is small building outlines. Set 2 is the plots of land which the buildings sit. There are over 2000 of these entries (Its a small village).

I am trying to figure out the way that grasshopper sorts lists using the sort list tool. I basically want to calculate the area of the buildings and the individual plot sizes and then calculate the percentage of plot surrounding the building (so basically the difference but in a percentage not m2). The basic maths of this is fine, what I cant get grasshopper to do is match the correct building with the correct plot from the the list of 2000 values!! Does anyone know how to do this?

The final stage of the process is to then extrude each plot according to the percentage calculated. This part is also fine. The problem currently is that grasshopper doesn't understand which value to match from each list.

The current algorithm looks like this:

I have tried just sorting the lists but it doesn't seem to be sorting them in the same order!

Any help with this would be greatly appreciated!

Thanks

J

Without seeing the Rhino file it's a little hard to tell you how to solve your problem, but the "Sort List" component sorts the list you input numerically from the lowest to the highest I believe.

Is the relationship of the Buildings and plots 1 to 1?  Meaning is there one building in every one plot? or does it vary?

Hi, thanks for your help.

The rhino file looks like this, generally there is 1 building per plot, but sometimes there are more yes.

So each plot and each building is a separate polygon/curve. I have used the area plug in GH which generates a centre point also. I was wondering whether i could match the buildings to the plots by the centre points using distance, but i'm not sure how to go with that either.

If the buildings and plots were 1 to 1 would there be an easier solution?

Thanks

• Add Photos
• View All

## Videos

• ### Beam forces visualized on meshes in Emu 1.1.0

Added by emlplsn

• ### Grasshopper Tutorial (Canton Tower)

Added by Parametric House

• ### df_envimet + MorphoMesh - How to add windows to buildings

Added by Antonello Di Nunzio

• ### Design and the past

Added by Benson Sanga

• ### Grasshopper Tutorial - Interior Design

Added by Parametric House

• ### Grasshopper Tutorial - Building Facade

Added by Parametric House

• Add Videos
• View All

© 2019   Created by Scott Davidson.   Powered by