From: Christopher R. Barry
Subject: The Right Way to do multiple sorted displaced indices to the same data in Lisp.
Date: 
Message-ID: <87puuqlx4z.fsf@2xtreme.net>
I get the feeling I'm probably overlooking something obvious, but
until a few hours ago when I started this project it's been a sorta
long time since I last programmed (been getting a lot more into
mathematics lately, though I'm still majoring CS, but I digress...).
Anyways, I convinced the teacher of my current course to let me use
Lisp instead of C++ or Java. A major part of the program involves
using multiple arrays that contain references to one array whose
contents are filled with data structures created during reading in a
file. The displaced arrays need to be sorted using a different test
for each one. My dilemna is this:


  First we have the master array with the structures:

    #(#S(foo-structure :slot-1 blah :slot-2 blah ...)
      #S(foo-structure :slot-1 blah :slot-2 blah ...)
      #S(foo-structure :slot-1 blah :slot-2 blah ...)
      NIL NIL NIL ....)

  Then we have displaced arrays that look the same as the above one
  that need to be sorted in terms of SLOT-1, SLOT-2, etc.... The code
  would look like:

  (sort *displaced-array-1* #'predicate-1 :key #'foo-structure-slot-1)
  (sort *displaced-array-2* #'predicate-2 :key #'foo-structure-slot-2)
  (sort *displaced-array-3* #'predicate-3 :key #'foo-structure-slot-3)
  ...
  ...

The problem is that I don't know how many data structures I will need
in advance, so if I use an array of size 1000, then I might have 700
NILs in the array that I don't want SORT to see for efficiency and
because the structure slot accessor will generate an error if given a
NIL. I thought about creating the displaced arrays at runtime with
their size set to the number of structure entries in the master array
and then passing those to sort, but runtime creation of the displaced
arrays isn't necessary in other languages (and probably not in Lisp
either if my head was working right, but it's been a good while...).

Anyways, a little hand-holding about the elegant way to do multiple
sorted displaced indices to the same shared data in Lisp would really
be appreciated.

Thank you,
Christopher

From: Christopher R. Barry
Subject: Wait.... Re: The Right Way to do multiple sorted displaced indices to the same data in Lisp.
Date: 
Message-ID: <87n1pulsvk.fsf@2xtreme.net>
······@2xtreme.net (Christopher R. Barry) writes:

I just thought that fill pointers should do the trick....

Feels good to be programming again....

Christopher
From: Christopher R. Barry
Subject: Never mind Re: The Right Way to do multiple sorted displaced indices to the same data in Lisp.
Date: 
Message-ID: <87iu0ilq4t.fsf@2xtreme.net>
······@2xtreme.net (Christopher R. Barry) writes:

>   (sort *displaced-array-1* #'predicate-1 :key #'foo-structure-slot-1)
>   (sort *displaced-array-2* #'predicate-2 :key #'foo-structure-slot-2)
>   (sort *displaced-array-3* #'predicate-3 :key #'foo-structure-slot-3)

Just wanted to mention that I did not mean Common Lisp displaced
arrays (:DISPLACED-TO ...). Plain old vectors with fill-pointers did
the trick quite fine and the critical portion of the program now runs
smooth.

Christopher