nancygold's Journal
 
[Most Recent Entries] [Calendar View] [Friends View]

Sunday, May 5th, 2024

    Time Event
    2:57a
    Guy L. Steele
    Beside his work on Common Lisp and Scheme, he also published a hash function as part of JVM:
    // [1]: Guy L. Steele, Jr., Doug Lea, and Christine H. Flood. 2014.
    // Fast splittable pseudorandom number generators.
    uint32_t splitmix32(uint32_t index, uint32_t seed) {
      uint32_t z = (seed + index*0x9e3779b9);
      z = (z ^ (z >> 16)) * 0x85ebca6b;
      z = (z ^ (z >> 13)) * 0xc2b2ae35;
      return z ^ (z >> 16);
    }
    


    compared to usual hashes, it has two arguments: the index and the seed.
    The idea is to have a virtual O(1) addressable array of hashes corresponding to some seed hash.

    Beside hashtables, it is useful for a lot of stuff.
    The most basic use is distributing byte values over the entire 32bit or 64bit word range.
    I personally use it to provide random numbers for each world cell, without storing these numbers in memory.
    I also use it create random number of each world's update cycle.
    It is even more useful when you have to sync hash generation across several threads or agents.

    Obviously you can use any hash function to turn index into a hash, but this one is super fast (for video game use), yet gives good distributions:
    https://lemire.me/blog/2017/08/22/testing-non-cryptographic-random-number-generators-my-results/

    Current Mood: amused
    12:24p
    People insist I'm a toxic person
    But I'm just telling truth.

    If you're an ugly freak, how come you got a nerve to give public speeches?


    1:06p
    New Speedrun Ideas
    Easy: kill all redguards in Morrowind
    Hard: kill all ugly NPCs in Morrowind



    Current Mood: amused
    1:41p
    Why my JRPG character misses several times in a row with 95% hit chance?


    Current Mood: amused
    9:30p
    Any sub O(n^2) soluton?
    Latest FizzBuzz:
    https://leetcode.com/problems/the-skyline-problem/

    can you find an O(n*log2(n)) solution?

    My O(n^2) solution (inner for loop gives the square)
      Input: [2 9 10] [3 7 15] [5 12 12] [15 20 10] [19 24 8]
      Output:
      Open!
      CurId MaxY -1
      for X,Y,Id,End Input.i{[@?1 ?0]}{[?0 ?2 ?3 0],[?1 ?2 ?3 1]}.j.sortBy(?0):
        less End:
          Open.Id = Y
          if MaxY < Y:
            [Id Y](:&CurId,&MaxY)
            push X,Y Output
          pass
        Open.del Id
        less Id><CurId: pass
        [-1 -1](:&CurId,&MaxY)
        less Open.n: | push X,0 Output; pass
        Open.l.maxf(?1)(:[&CurId &MaxY])
        push X,MaxY Output
    
      say Output.f
    





    Current Mood: amused

    << Previous Day 2024/05/05
    [Calendar]
    Next Day >>

About LJ.Rossia.org