Bill Roper (billroper) wrote,
Bill Roper

Let Me Check That Out

We had some code that was running slowly across a list of some 20K members. It turns out that the reason it was running slowly was that rather than just adding new members, we checked each member of the list to make sure that we weren't adding a *duplicate* member with the new add. This works fine for short lists, but is pretty much abominable by the time you're adding 20K members.

"Well," I said to myself. That's easy enough to fix. I can just add a hashCode() (and matching equals()) method to the class for the members that are being added to the list; then add a HashSet to keep track of what's already in the list, because that will look things up in a hurry. In fact, we should just make a class that welds a HashSet to the side of our ArrayList, because I know I've solved a similar problem before and we may as well not have to *keep* solving it."

I then paused and ran a brief search.

Right. ListOrderedSet in Apache Commons. I figured someone else had had this problem before...

Did I mention how nice it is to be working in a language with modern libraries available?
Tags: computers, java, musings, work

  • Reporting In

    Gretchen and I went to the doctor for a fasting blood draw this morning. We'll see how the results are. This afternoon, Gretchen went *back* in that…

  • Steps

    Today is better than yesterday. Still short on solutions, but maybe I can get some time to sort things out. Thanks, folks.

  • Well, That Escalated Quickly

    Today could have been better. Much better.

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded