Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28165

Re: 64-bit hashing function

From markspace <markspace@nospam.nospam>
Newsgroups comp.lang.java.programmer
Subject Re: 64-bit hashing function
Date 2014-04-21 11:46 -0700
Organization A noiseless patient Spider
Message-ID <lj3p1i$clm$1@dont-email.me> (permalink)
References <kfh8l9p1hhphqv5l62am7if9bhnotfse6j@4ax.com> <5354c699$0$6708$9b4e6d93@newsspool2.arcor-online.net> <45i9l9tq8ng6dk1lbfoc97tcj5gbd09iu7@4ax.com> <5354f836$0$6715$9b4e6d93@newsspool2.arcor-online.net> <34kal9pept6fvrf6226lbcpe9j03nd5eh7@4ax.com>

Show all headers | View raw


On 4/21/2014 10:09 AM, Roedy Green wrote:
>
> here is my first cut at the code. I have not run it yet

Yeow, this is kinda terrible.  My main thoughts are:

1. Way too much static initialization.  Just referencing the class in 
any fashion will cause the entire cache to be read into memory.

2. Several of your static constants are ripe for a Look Up Service 
and/or Injection.  Cf Martin Fowler's discussion of these design patterns.

<http://martinfowler.com/articles/injection.html>

3. You should leave yourself some wiggle room to move from flat files to 
a simple database in the future.  Since it's your code you can just gut 
the thing and re-write it but it doesn't look easy.

> import com.mindprod.common17.ST;

Numbering package names == hard to remember.  Use a better name for 
what's common in this package other than "17".

> public classLazy

You said it, not me, ;-)

>      {
>      static
>          {
>          load();
>          }

Evil!!!

>
>      static
>          {
>
>          // arrange for save to be run at shutdown.
>          Runtime.getRuntime().addShutdownHook( new Thread()

Shutdown hooks are pretty gross, imo.  Is there a better way?

>      /**
>       * look up filename hash-32 to timestamp
>       */
>      private static HashMap<Integer, Long> lookup;

???

>      private static void load()
>          {

Way too many static methods here.  What happened to instantiating a 
class like normal folks?

>      private static void save()

Same comment.

>      public static boolean isAlreadyDone( File file )
>          {

There are a lot of side effects in this method, including removing stale 
entries.  Consider refactoring this into smaller methods.

>
>          // if all is well ,the last modified date should not have
> changed since we recorded the file as
>          // successfully processed.
>          if ( file.lastModified() > timestampL + slop )
>              {
>
>              // the file has been modified since we last processed it.
>              // we will have to reprocess it.
>              // This cache entry is useless. We might as well get rid
> of it to save some space.

I'm really curious as to what, exactly, you are caching here, and why. 
What's the point of keeping filenames in a hash map?

I also think your conflating a basic operation, like caching, with other 
operations that are specific your your app domain, like "prune filename 
E:/mindprod/jgloss/jdk.html down to jgloss/jdk".  Filename manipulation 
belongs in a higher level of the code, the cache should just do caching.

Cf. other cache designs, like the one built into Android:

<http://developer.android.com/reference/android/util/LruCache.html>

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-20 15:15 -0700
  Re: 64-bit hashing function Arne Vajhøj <arne@vajhoej.dk> - 2014-04-20 19:37 -0400
  Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-20 22:18 -0700
  Re: 64-bit hashing function Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-04-21 09:19 +0200
    Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 00:51 -0700
      Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 02:05 -0700
        Re: 64-bit hashing function taqmcg@gmail.com - 2014-04-21 11:49 -0700
          Re: 64-bit hashing function taqmcg@gmail.com - 2014-04-21 12:01 -0700
        Re: 64-bit hashing function wolfgang zeidler <invalid@invalid.invalid> - 2014-04-22 20:42 +0200
      Re: 64-bit hashing function Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-04-21 12:51 +0200
        Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 06:31 -0700
          Re: 64-bit hashing function Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-04-21 16:40 +0200
            Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 20:45 -0700
              Re: 64-bit hashing function Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-04-22 09:46 +0200
        Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 06:38 -0700
          Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 06:55 -0700
        Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 10:09 -0700
          Re: 64-bit hashing function markspace <markspace@nospam.nospam> - 2014-04-21 11:46 -0700
            Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 20:55 -0700
              Re: 64-bit hashing function markspace <markspace@nospam.nospam> - 2014-04-22 08:39 -0700
            Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 20:56 -0700
            Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 21:05 -0700
              Re: 64-bit hashing function markspace <markspace@nospam.nospam> - 2014-04-22 08:15 -0700
            Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-25 02:29 -0700
          Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-21 20:53 -0700
          Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-05-08 10:12 -0700
            Re: 64-bit hashing function Simon Lewis <simonlewis2001@gmail.com> - 2014-05-08 21:27 +0200
  Re: 64-bit hashing function rossum <rossum48@coldmail.com> - 2014-04-23 09:57 +0100
    Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-04-25 04:08 -0700
      Re: 64-bit hashing function Mike Amling <mamling@chaff.us> - 2014-05-05 11:03 -0500
        Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-05-29 16:00 -0700
        Re: 64-bit hashing function Roedy Green <see_website@mindprod.com.invalid> - 2014-05-29 16:16 -0700

csiph-web