Post Reply 
HP 48GX - Store Coordinates in a List
04-13-2021, 07:44 AM (This post was last modified: 04-13-2021 07:59 AM by Han.)
Post: #11
RE: HP 48GX - Store Coordinates in a List
Hopefully this reply isn't too late. Please allow me to explain how I understand your goal to see if our thinking is in alignment. You wish to have a list whose elements are themselves lists (point data). It is possible that you may have several of these types of lists (organized as point types) which might also be incorporated together as a list. So something like:

Code:
{
  { { point 1-1 data }, { point 1-2 data }, ..., { point 1-n data} } // type 1 with n points
  { { point 2-1 data }, { point 2-2 data }, ..., { point 2-m data } } // type 2 with m points
   ...
}

I recommend simply have one list of just points, where the point data itself contains the "type".
Code:
{
  {100 [5000 5000] "PROP COR"}
  {500 [5200 5100] "BLDG COR"}
}

Then keep a string that indexes these points for fast searching. If you wish to only use A-Z and a-z as your characters, that gives you \( 52^2 = 2704 \) points as you previously calculated. Then your string of indices would look like "BwJg" (assuming \( B=1 \) and \( w=48\) to get \(1\cdot 52^1 + 48\cdot 52^0 =100\); similarly \( J = 9 \) and \( g = 32 \) for \( 9\cdot 52^1 + 32\dot 52^0 = 500 \)).

Without the use of index strings, you would have to check each individual point (which is itself a list) and skip the current point (assuming no match) and go check the next point. Due to the way lists are stored internally, this is an extremely slow process (skipping a list means skipping each individual object within the list). So for example, if you wanted to know where point labeled 500 is stored (or if it even exists), you would have to check the first point, see that it is is not labeled as 500, and then "skip" the first point to check the next point. Strings are just a sequence of characters, and skipping characters is extremely fast. The number of "skips" is the position within the list (with perhaps +1 depending on whether your index starts at 1).

A second string would be used to sort your list. This string would also be composed of 2-character indices, but the value would be the index within the point list. In other words, we sort the point labels (100 and 500) and store the position. With only two points, your string would be "ABAC" since ( \( A=0, B=1, C=2 \) so that \( AB = 0\cdot 52^1 + 1\cdot 52^0 = 1\) and \( AC = 0\cdot 52^1 + 2\cdot 52^0 = 2 \)). Let's suppose we add a third point to the end of the existing point list, and that its point number is 300. Then the first string "BwJg" becomes "BwJgFo" (\( F=5 \) and \( o = 40 \) so \( Fo = 5\cdot 52^1 + 40\cdot 52^0 = 300 \)). We simply "tack on" the new point and store its label into the string. The second string would have to be modified to "ABADAC" so that the second 2-character code "AD" (which is 3 in base 10) points to the third position in the original point data list. In order to insert "AD" into an already sorted string of indices, you would need to apply a binary search (pretty fast) as Joe Horn mentioned, and split and concatenate substrings.

Thus if you wanted the label of the \(k\)-th unsorted point, you would use the first string and extract the \(2k\)-th and \(2k+1\)-th characters, convert into decimal. If you want the \( k\)-th sorted point in the data point list, then you would use the second string instead. After converting the 2-character string to decimal form, use this value (call it \( p \)) and extract the \( p\)-th element of the point list. And lastly, if you wanted to find the point whose label is \( k \) itself, just start at the beginning of the first string, and keep extracting 2 characters at a time, convert to decimal form, and see if the resulting value is equal to \( k \). The number of skips (call it \( p \)) is the position of the \( k\)-th label within the point list; just extract the \( p \)-th element from your point list.

Gaps in point labels will not matter. And you will not have to sort your points list -- it will be ordered in chronological order (the last point was the last added). Your second string will keep the positions of the sorted labels.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 48GX - Store Coordinates in a List - Han - 04-13-2021 07:44 AM



User(s) browsing this thread: 1 Guest(s)