Re: Algorithm
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 06:20:32 GMT
On Sat, 29 Oct 2005 19:59:36 -0600, "Luc The Perverse"
<sll_noSpamlicious_z_XXX_m@xxxxxxxxxx> wrote, quoted or indirectly
quoted someone who said :
>
>Yes that was the plan. My problem is coming when I want to delete the same
>object from each of the three arrays at the same time. (I will have found
>it by looking through only one of the arrays.
Sorted arrays are not insert/delete friendly. They are a batch-think
tool.
Have a look at the ArrayList.remove method. You can do it by index or
by object. By object requires a linear scan of each of the three
arrays. There is then a block move to shuffle all high elements down
one in each array.
If this is something you don't do often, delete the object from the
original pool, recreate the three arrays and resort them. This may
sound extravagent, but the same code will work no matter how many
arrays and sub collections you create. You don't need to carefully
maintain the delete logic.
Another approach is instead of removing the object, just invalidate it
so that it is ignored ever after, including any rebuild of the array
where it will be permanently dropped.
You might be interested in my SortedArray class that handles many of
these things for you.
See http://mindprod.com/products1.html#SORTED
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- Follow-Ups:
- Re: Algorithm
- From: Luc The Perverse
- Re: Algorithm
- Prev by Date: Re: protocol question
- Next by Date: Re: Thunerbird help... [not java related , but please help if you can!]
- Previous by thread: Re: GIF Transcoders for ImageIO?
- Next by thread: Re: Algorithm
- Index(es):
Relevant Pages
|