From comp.sys.handhelds Fri Feb  8 12:58:58 1991
Path: mentor.cc.purdue.edu!noose.ecn.purdue.edu!samsung!sol.ctr.columbia.edu!spool.mu.edu!sdd.hp.com!hplabs!hplabsb!seroussi
From: seroussi@hplabsb.HP.COM (Gadiel Seroussi)
Newsgroups: comp.sys.handhelds
Subject: HP48 compact arrays
Message-ID: <5966@hplabsb.HP.COM>
Date: 7 Feb 91 19:17:48 GMT
Organization: Hewlett Packard Laboratories, Palo Alto
Lines: 212

The binary directory (in ASC-> format) appended at the end of this message
uses HP48 linked arrays to implement "compact arrays" of positive integers. 
These arrays allow you to store large tables of positive binary integers using 
significantly less storage than would be required with either real arrays or 
lists of binaries, with an access time comparable to that of real arrays (much 
faster than lists of binaries).
A compact array shows on the stack as "Linked Array", and cannot be edited
directly (conversion routines are provided).
The internal structure of a compact array is as follows:
<02a0a> - header (5 nib)
<size>  - size of object excluding header (5 nib)
<isize> - size of array elements, in nibbles (5 nib)
<n>     - number of elements (5 nib)
<element 1> <element 2> ..... <element n>  (<isize> nibbles each).

Other headers could have been choosen but "linked array" was unused enough to
justify the choice (and choices like "code" or "string" would be confusing).

The following variables are included:

IGETB: retrieve an element of the array, as a binary number.

	2: A (compact array)
	1: k (Real)          ----> 1: A(k)  (binary)

IGET: retrieve an element of the array, as a real number.

	2: A (compact array)
	1: k (Real)          ----> 1: A(k)  (Real).

If k <= 0, the number of elements of the array is returned. Subscript range
is checked.

IPUT: store a value in the array.

	3: A (compact array)
	2: k (Real)
	1: x (Real or binary)  ----> 1: A (compact array, with A(k)=x).

Subscript range is checked, k <= 0 is not allowed. The value x is truncated
to the size of the array elements.

ICON: generate a compact array with constant elements.

	3: n (Real)
	2: isize (Real)
	1: c (Real or binary)  ----> 1: A (compact array).

A has n elements, isize nibbles each, all set to the value c. While it is 
legal to set isize > 16, the access routines will only handle up to 16 nibble 
values.

ISIZE: find out the value of <isize>.

	1: A (compact array)   ----> 1: isize (Real)

ITOA: Convert compact array to real array.

	1: A (compact array)   ----> 1: RA (Array of Real).

ITOB: Convert compact array to list of binaries.

	1: A (compact array)   ----> 1: BL (List of Binary).

ATOI: Convert real array to compact array.

	2: RA (Array of Real)  
	1: isize (real)        ----> 1: A (compact array)

BTOI: Convert list of binaries to compact array.

	2: BL (List of Binary)
	1: isize (real)        ----> 1: A (compact array)

For both ATOI and BTOI, if isize == 0, the least number of nibbles will be 
used that can accomodate the largest value in RA or BL (resp.).

BMAX: Find the largest value in a list of binaries (aux. function).

p.small: an example of a compact array. A list of the first 1000 prime numbers.
	It takes 2010 bytes of storage, compared to 8012.5 bytes for a real
	array, or around 7000 bytes for a "well packed" list of binaries
	(which ITOB will NOT produce).

Other remarks:
1. The conversion routines are written in user language. Since I consider
   them "one-time" events, no special effort was made to make them faster.
2. All access routines are affected by the current setting of the binary
   word size (set word size >= isize for things to work properly).

This package was developed for a Version D ROM. It may or may not work on
yours. It may or may not destroy your data and/or your calculator.
Use it at your own risk. No warranties of any kind.

Enjoy,

Gadiel Seroussi
HP Labs (but no relation to Corvallis)