Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
Container Registry
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
6e628c49
Commit
6e628c49
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Replace naive and teribble hash function with djb2.
parent
ffb5cfc8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/makeqstrdata.py
+2
-2
2 additions, 2 deletions
py/makeqstrdata.py
py/qstr.c
+5
-3
5 additions, 3 deletions
py/qstr.c
with
7 additions
and
5 deletions
py/makeqstrdata.py
+
2
−
2
View file @
6e628c49
...
...
@@ -18,9 +18,9 @@ codepoint2name[ord('/')] = 'slash'
# this must match the equivalent function in qstr.c
def
compute_hash
(
qstr
):
hash
=
0
hash
=
5381
for
char
in
qstr
:
hash
+
=
ord
(
char
)
hash
=
(
hash
*
33
)
^
ord
(
char
)
return
hash
&
0xffff
def
do_work
(
infiles
):
...
...
This diff is collapsed.
Click to expand it.
py/qstr.c
+
5
−
3
View file @
6e628c49
...
...
@@ -18,7 +18,7 @@
// A qstr is an index into the qstr pool.
// The data for a qstr contains (hash, length, data).
// For now we use very simple encoding, just to get the framework correct:
// - hash is 2 bytes (s
imply the sum of data bytes
)
// - hash is 2 bytes (s
ee function below
)
// - length is 2 bytes
// - data follows
// - \0 terminated (for now, so they can be printed using printf)
...
...
@@ -28,10 +28,12 @@
#define Q_GET_LENGTH(q) ((q)[2] | ((q)[3] << 8))
#define Q_GET_DATA(q) ((q) + 4)
// this must match the equivalent function in makeqstrdata.py
machine_uint_t
qstr_compute_hash
(
const
byte
*
data
,
uint
len
)
{
machine_uint_t
hash
=
0
;
// djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
machine_uint_t
hash
=
5381
;
for
(
const
byte
*
top
=
data
+
len
;
data
<
top
;
data
++
)
{
hash
+=
*
data
;
hash
=
((
hash
<<
5
)
+
hash
)
^
(
*
data
);
// hash * 33 ^ data
}
return
hash
&
0xffff
;
}
...
...
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