Sunday, July 10

PGP - Part 3 "Internal Data Structures"

Now what?

In the last post we created the code needed to generate a large number of people and those peoples "randomly" generated genders. Our current code creates a visual representation of that data, but after it is created their is little we can do with it. We are currently processing the data as we create it, and not actually storing it afterwards.

How to store people...

Currently we will be storing every person's data in a single array for the sake of simplicity. While this will work at the moment. This will not be the final data structure. Javascript code in this post will be colored blue.

var people = [];

Now we have to remember to create a new person object for each person we create.

var person = {};

Every person will need a unique identifying number we can use to index and find them. Since we are storing everything in an array, we will simply use the persons position in the array as their id.

person.uniqueId = people.length;

Finally we get to the start of the fun part of this experiment. Instead of storing massive amounts of generated data for each person we create. We will just store a unique "DNA" number which we can use to generate all that persons data when we need it. This way if we never actually manipulate this person their stored data will only be their uniqueId, and their DNA value.

person.DNA = Math.round( prng(4124532765) );  // Maximum number of unique people

Now here is where I would normally embed a link to a pen created to demonstrate the code I introduced above. Since the code so far is used behind the scenes, there really is not much that would be shown.

Proof of current concept...

Bellow is link to another pen which demonstrates what I have been discussing here. Now this one generates only the basic person, with no extra generated content. And when you hover over a box that is displayed it will generate the extra information for the person at that time.

If you choose not to hover over any of the boxes, I have it set to automatically generate a new person's information every 500 milliseconds.

Continue with ...


Post a Comment