Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
cmucl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carl Shapiro
cmucl
Commits
6cc34caa
Commit
6cc34caa
authored
34 years ago
by
wlott
Browse files
Options
Downloads
Patches
Plain Diff
Rewrote sxmash to keep out of bignum land.
parent
60e852dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
code/hash.lisp
+31
-23
31 additions, 23 deletions
code/hash.lisp
with
31 additions
and
23 deletions
code/hash.lisp
+
31
−
23
View file @
6cc34caa
...
...
@@ -359,14 +359,22 @@
(
eval-when
(
compile
eval
)
;;; We could use a rotate function here, but that isn't in ucode, so
;;; instead we Xor the number with a lsh'ed version of itself...
;;;
(
defmacro
sxmash
(
x
num
)
(
let
((
n-x
(
gensym
)))
`
(
let
((
,
n-x
,
x
))
(
declare
(
fixnum
,
n-x
))
(
abs
(
logxor
(
the
fixnum
(
ash
,
n-x
,
num
))
,
n-x
)))))
(
defconstant
sxmash-total-bits
26
)
(
defconstant
sxmash-rotate-bits
7
)
(
defmacro
sxmash
(
place
with
)
(
let
((
n-with
(
gensym
)))
`
(
let
((
,
n-with
,
with
))
(
declare
(
fixnum
,
n-with
))
(
setf
,
place
(
logxor
(
ash
,
n-with
,
(
-
sxmash-rotate-bits
sxmash-total-bits
))
(
ash
(
logand
,
n-with
,
(
1-
(
ash
1
(
-
sxmash-total-bits
sxmash-rotate-bits
))))
,
sxmash-rotate-bits
)
(
the
fixnum
,
place
))))))
(
defmacro
sxhash-simple-string
(
sequence
)
`
(
%primitive
sxhash-simple-string
,
sequence
))
...
...
@@ -391,32 +399,27 @@
(
hash
2
))
((
or
(
atom
sequence
)
(
=
index
sxhash-max-len
))
hash
)
(
declare
(
fixnum
hash
index
))
(
setq
hash
(
sxmash
(
logxor
hash
(
internal-sxhash
(
car
sequence
)
(
1+
,
depth
)))
7
)))))
(
sxmash
hash
(
internal-sxhash
(
car
sequence
)
(
1+
,
depth
))))))
)
; eval-when (compile eval)
;;; This multi-level type dispatch is faster, since typecase doesn't
;;; turn into a real dispatch.
;;;
(
defun
sxhash
(
s-expr
)
"Computes a hash code for S-EXPR and returns it as an integer."
(
internal-sxhash
s-expr
0
))
(
defun
internal-sxhash
(
s-expr
depth
)
(
typecase
s-expr
(
array
(
typecase
s-expr
(
simple-string
(
sxhash-simple-string
s-expr
))
(
string
(
sxhash-string
s-expr
))
(
t
(
array-rank
s-expr
))))
(
symbol
(
sxhash-simple-string
(
symbol-name
s-expr
)))
;; The pointers and immediate types.
(
list
(
sxhash-list
s-expr
depth
))
(
fixnum
(
abs
s-expr
))
#+
nil
(
structure
???
)
;; Other-pointer types.
(
simple-string
(
sxhash-simple-string
s-expr
))
(
symbol
(
sxhash-simple-string
(
symbol-name
s-expr
)))
(
number
(
etypecase
s-expr
(
integer
(
ldb
(
byte
23
0
)
s-expr
))
...
...
@@ -428,6 +431,11 @@
(
internal-sxhash
(
denominator
s-expr
)
0
))))
(
complex
(
the
fixnum
(
+
(
internal-sxhash
(
realpart
s-expr
)
0
)
(
internal-sxhash
(
imagpart
s-expr
)
0
))))))
(
array
(
typecase
s-expr
(
string
(
sxhash-string
s-expr
))
(
t
(
array-rank
s-expr
))))
#+
nil
(
compiled-function
(
%primitive
header-length
s-expr
))
;; Everything else.
(
t
(
%primitive
make-fixnum
s-expr
))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment