This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2016-2022 Yegor Bugayenko | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
+alias org.eolang.collections.bytes-as-array | ||
+home https://github.com/objectionary/eo-collections | ||
+package org.eolang.collections | ||
+rt jvm org.eolang:eo-collections:0.0.0 | ||
+version 0.0.0 | ||
|
||
# Hash code - the pseudo-unique integer representation of an object. | ||
# | ||
# Here "h" must be an object that can be converted to bytes via "as-bytes" | ||
# object. | ||
[h] > hash-code-of | ||
switch > @ | ||
* | ||
eq. | ||
h.as-bytes > h-as-bytes! | ||
01- | ||
1232 | ||
* | ||
h-as-bytes.eq 00- | ||
1237 | ||
* | ||
h-as-bytes.size.eq 8 | ||
as-int. | ||
xor. | ||
h-as-bytes | ||
h-as-bytes.right 32 | ||
* | ||
TRUE | ||
[] | ||
[acc index bytes zero-as-bytes] > rec-hash-code | ||
if. > @ | ||
index.eq bytes.length | ||
acc | ||
rec-hash-code | ||
plus. | ||
times. | ||
31 | ||
acc | ||
as-int. | ||
right. | ||
zero-as-bytes.and | ||
bytes.at index | ||
54 | ||
index.plus 1 | ||
bytes | ||
zero-as-bytes | ||
|
||
0.as-bytes > zero-as-bytes! | ||
|
||
rec-hash-code > @ | ||
1 | ||
0 | ||
bytes-as-array | ||
h-as-bytes | ||
zero-as-bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2021-2022 Yegor Bugayenko | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
+alias org.eolang.collections.hash-code-of | ||
+alias org.eolang.hamcrest.assert-that | ||
+alias org.eolang.math.number | ||
+home https://github.com/objectionary/eo-collections | ||
+junit | ||
+package org.eolang.collections | ||
+version 0.0.0 | ||
|
||
# @todo #156:30min Add more tests for hash-code-of object. | ||
# It would be interesting to test floating numbers and, maybe, big numbers | ||
# (or some corner cases) | ||
[] > hash-code-bools-is-integer | ||
assert-that > @ | ||
and. | ||
is-int. | ||
number | ||
hash-code-of TRUE | ||
is-int. | ||
number | ||
hash-code-of FALSE | ||
$.equal-to TRUE | ||
|
||
[] > hash-of-int-is-int | ||
assert-that > @ | ||
is-int. | ||
number | ||
hash-code-of 42 | ||
$.equal-to TRUE | ||
|
||
[] > hash-codes-of-the-same-numbers-are-equal | ||
42 > forty-two! | ||
assert-that > @ | ||
hash-code-of forty-two | ||
$.equal-to | ||
hash-code-of forty-two | ||
|
||
[] > hash-code-of-the-same-strings-are-equal | ||
"hello" > str! | ||
assert-that > @ | ||
hash-code-of str | ||
$.equal-to | ||
hash-code-of str | ||
|
||
[] > hash-code-of-different-numbers-are-different | ||
assert-that > @ | ||
hash-code-of 42 | ||
$.not | ||
$.equal-to | ||
hash-code-of 24 |
548fa9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
156-e1f116f6
discovered insrc/main/eo/org/eolang/collections/map.eo
) and submitted as #175. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.548fa9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
156-50c73486
discovered insrc/test/eo/org/eolang/collections/hash-code-of-tests.eo
) and submitted as #176. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.