annotate modules/sets.tp @ 263:98147071baf6

Add support for llMessage definitions in buildMethodTables
author Michael Pavone <pavone@retrodev.com>
date Mon, 14 Jul 2014 09:30:31 -0700
parents a2d2d8e09291
children
rev   line source
pavone@80 1 #{
pavone@80 2 hash <- {
pavone@80 3 empty <- #{
pavone@80 4 empty? <- { true }
pavone@80 5 }
pavone@81 6 size <- 0
pavone@81 7 hashdiffs <- #[0]
pavone@80 8 #{
pavone@80 9 buckets <- #[empty empty empty empty]
pavone@125 10 size <- 0
pavone@80 11 contains? <- :object {
pavone@80 12 hv <- object hash
pavone@80 13
pavone@80 14 notdone <- true
pavone@81 15
pavone@81 16 basehash <- hv
pavone@80 17 i <- 0
pavone@80 18 ret <- false
pavone@81 19 while: { if: notdone { i < (hashdiffs length) } } do: {
pavone@81 20 hv <- basehash + (hashdiffs get: i)
pavone@80 21 trunc <- hv % (buckets length)
pavone@80 22 if: trunc < 0 { trunc <- 0 - trunc }
pavone@80 23 bucketval <- (buckets get: trunc)
pavone@80 24 if: (bucketval empty?) {
pavone@80 25 notdone <- false
pavone@80 26 } else: {
pavone@80 27 if: (bucketval eq: hv) {
pavone@80 28 ret <- true
pavone@80 29 notdone <- false
pavone@80 30 }
pavone@80 31 }
pavone@80 32 i <- i + 1
pavone@80 33 }
pavone@80 34 ret
pavone@80 35 }
pavone@80 36 add <- :object {
pavone@80 37 addHash: (object hash)
pavone@80 38 }
pavone@80 39 addHash <- :hv {
pavone@80 40 makeBucket <- :hv {
pavone@80 41 #{
pavone@80 42 empty? <- { false }
pavone@80 43 v <- hv
pavone@80 44 eq <- :other { v = other }
pavone@80 45 }
pavone@80 46 }
pavone@80 47 notdone <- true
pavone@81 48 basehash <- hv
pavone@80 49 i <- 0
pavone@81 50 while: { if: notdone { i < (hashdiffs length) } } do: {
pavone@81 51 hv <- basehash + (hashdiffs get: i)
pavone@80 52 trunc <- hv % (buckets length)
pavone@80 53 if: trunc < 0 { trunc <- 0 - trunc }
pavone@80 54 bucketval <- (buckets get: trunc)
pavone@80 55 if: (bucketval empty?) {
pavone@81 56 size <- size + 1
pavone@80 57 buckets set: trunc (makeBucket: hv)
pavone@80 58 notdone <- false
pavone@80 59 } else: {
pavone@80 60 if: (bucketval eq: hv) {
pavone@80 61 notdone <- false
pavone@80 62 }
pavone@80 63 }
pavone@80 64 i <- i + 1
pavone@80 65 }
pavone@80 66 if: notdone {
pavone@81 67 newsize <- (buckets length) * 3 + 1
pavone@81 68 lastdiff <- hashdiffs get: ((hashdiffs length) - 1)
pavone@81 69 if: lastdiff <= 0 {
pavone@81 70 hashdiffs append: ((0 - lastdiff) + 1)
pavone@81 71 } else: {
pavone@81 72 hashdiffs append: (0 - lastdiff)
pavone@81 73 }
pavone@80 74 newbucks <- #[]
pavone@125 75 newbucks resize: newsize
pavone@80 76 while: { (newbucks length) < newsize } do: {
pavone@80 77 newbucks append: empty
pavone@80 78 }
pavone@80 79 oldbucks <- buckets
pavone@80 80 buckets <- newbucks
pavone@125 81 size <- 0
pavone@80 82 foreach: oldbucks :idx el {
pavone@80 83 if: (not: (el empty?)) {
pavone@80 84 addHash: (el v)
pavone@80 85 }
pavone@80 86 }
pavone@80 87 addHash: hv
pavone@80 88 }
pavone@80 89 self
pavone@80 90 }
pavone@80 91 }
pavone@80 92 }
pavone@80 93 }