lemmy.mixdown.ca
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
cm0002@lemmy.world to Programmer Humor@programming.dev · 1 year ago

timeoutSort

lemmy.ml

message-square
8
link
fedilink
6

timeoutSort

lemmy.ml

cm0002@lemmy.world to Programmer Humor@programming.dev · 1 year ago
message-square
8
link
fedilink
alert-triangle
You must log in or register to comment.
  • Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    finally, sorting in linear time /s

  • Kairos@lemmy.today
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Race condition

  • mcmodknower@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I know this under the name sleepSort.

  • Dyskolos@lemmy.zip
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    6 months ago

    deleted by creator

  • Nat (she/they)@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    Wait till you find out how the runtime manages multiple concurrent timers

    • sus@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      it’s

      while (true) {
          let t = Date.now();
          if (timeoutMap.has(t)) timeoutMap[t]();
      }
      

      of course. Clearly O(n).

      disclaimer

      Feel free to use it. I guarantee it is bug free. Comes with express warranty. This notice is legally binding.

      • FooBarrington@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        1 year ago

        I found a way to optimize your code without affecting the result. By making it branchless, I was able to get my CPU to 100% utilization!

  • JargonWagon@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    I’m dumb, can someone ELI5 please?

    • scrion@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      The output is sorted due to the fact that for each number, a timer is started that prints out the number after waiting a number of milliseconds equal to said number.

      Therefore, 1 is printed first after delaying for 1 millisecond, 5 is printed second after 5 milliseconds etc.

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 990 users / day
  • 5.54K users / week
  • 7.83K users / month
  • 15.9K users / 6 months
  • 1 local subscriber
  • 33.9K subscribers
  • 2.48K Posts
  • 74K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org