Problem description:
I was reading a C++ book and I ran across something that is an alternative to looping through lists.
I was wondering what the DM equivalent would be and how to set one up - nodes.
Which is basically an item that then has sub items to the left and right.
The theory is that each level of a node that you do "down" eliminates up to half the items you have to look through.
so A leads to B and C, while B leads do D and E, and C leads to F and G, and so on.
I was curious how this could be applied to other things like atoms. It seems pretty useful. Any ideas?
ID:1875187
Jun 15 2015, 4:13 pm
|
|
node ftfy |
Nodes of what sort of data structure? A linked list? Double-linked list? Ring? Dequeue? Tree? Heap? BYOND can do all of those with datums.
It sounds like you're describing a binary search tree. Making your own trees can be useful. Although, BYOND already uses binary trees for associative lists, so wherever feasible you're better off relying on the internal behavior which is faster. |
This is all insightful but I think the closest answer was the one Lummox Jr gave with associative lists, could you show a small example of that?
I'm more interested in using it for things like finding players in a list or finding certain items in a list. |
Do you mean like Dictionaries ?
public Dictionary<string, int> Dic = new Dictionary<string, int>(); //Sets the dictionary You said that you read something in your C++ book ("I was reading a C++ book and I ran across something that is an alternative to looping through lists"). I guess that the book as an exemple of what it looks like. Could you post it for me please (so I can help you better)? I am much more familiar with C# than C++ but I'll give it a try. |
You might make a player dictionary that associates a player's key to the player's mob:
var key2mob[0] Then, given a key, you can instantly get the mob with that key with key2mob[that_key], instead of looping through and checking the key of every client. Something like that? |
I personaly don't like to work with C++ so please forgive me if I make any mistakes. A node in c# looks like this (I guess that a node in C++ is similar, at least it does the same thing):
I wrote a code in DM that does pretty much the same thing (it is the equivalente to the C++ and C# node system):
Thanks for the challenge :D
Hug,
,MistY