replace all trit representations from int[] to byte[]#879
replace all trit representations from int[] to byte[]#879GalRogozinski merged 3 commits intoiotaledger-archive:devfrom
Conversation
fix tests accordingly.
b0612d1 to
aa06b2e
Compare
| Hash hash = getRandomTransactionHash(); | ||
| TransactionViewModel transactionViewModel = new TransactionViewModel(trits, hash); | ||
| transactionViewModel.store(tangle); | ||
| assertArrayEquals(transactionViewModel.trits(), TransactionViewModel.fromHash(tangle, transactionViewModel.getHash()).trits()); |
There was a problem hiding this comment.
re-enabled test and fixed, could move to another PR if you want.
| Hash hash = getRandomTransactionHash(); | ||
| TransactionViewModel transactionViewModel = new TransactionViewModel(trits, hash); | ||
| transactionViewModel.store(tangle); | ||
| assertArrayEquals(transactionViewModel.getBytes(), TransactionViewModel.fromHash(tangle, transactionViewModel.getHash()).getBytes()); |
There was a problem hiding this comment.
re-enabled test and fixed, could move to another PR if you want.
| Transaction transaction = new Transaction(); | ||
|
|
||
| int[] trits = Arrays.stream(new int[TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE]).map(i -> seed.nextInt(3)-1).toArray(); | ||
| byte[] trits = new byte[TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE]; |
There was a problem hiding this comment.
getRandomTransaction impl. appears a few times, better to move to a Utils class.
but not part of this scope.
| TransactionViewModel.BRANCH_TRANSACTION_TRINARY_SIZE); | ||
| return trits; | ||
| } | ||
| public static int[] getRandomTransactionWithTrunkAndBranchValidBundle(Hash trunk, Hash branch) { |
There was a problem hiding this comment.
removed b/c not used.
GalRogozinski
left a comment
There was a problem hiding this comment.
I disliked the if hack to differentiate between the construction of bytes and trits.
If you want to save time I can agree on merging this as long as there is a github issue opened on this matter.
| } else { | ||
| return validate(trits, minWeightMagnitude, SpongeFactory.create(SpongeFactory.Mode.CURLP81)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Instead of this hack, perhaphs create two methods:
validateTrits and validateBytes.
The above change is just confusing (even though it works)...
| this.hash = hash; | ||
| weightMagnitude = this.hash.trailingZeros(); | ||
| transaction.type = FILLED_SLOT; | ||
| } |
There was a problem hiding this comment.
I would create two static factory methods:
createFromBytes and createFromTrits and make the constructor private.
There was a problem hiding this comment.
I'll open an issue on this. but it shouldn't block the goodness from this PR imo.
| @@ -16,7 +16,7 @@ public class ISSInPlace { | |||
| private static final int MIN_TRIT_VALUE = -1, MAX_TRIT_VALUE = 1; | |||
| private static final int MIN_TRYTE_VALUE = -13, MAX_TRYTE_VALUE = 13; | |||
There was a problem hiding this comment.
change from int to byte.
Your code works either way, but still...
| System.arraycopy(source, sourceOffset, dest, 0, dest.length); | ||
| this.tritSafe = new TritSafe(dest); | ||
| } | ||
| } |
There was a problem hiding this comment.
Again I would encourage the use of factory methods...
There was a problem hiding this comment.
I'll open an issue on this. but it shouldn't block the goodness from this PR imo.
| Transaction transaction = new Transaction(); | ||
|
|
||
| int[] trits = Arrays.stream(new int[TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE]).map(i -> seed.nextInt(3)-1).toArray(); | ||
| byte[] trits = new byte[TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE]; |
| } | ||
|
|
||
| return out; | ||
| } |
There was a problem hiding this comment.
I agree that this is more reasdable than the one liner.
Another option was to not change the code and just add new lines before each aggregate call.
Anyhows, both variations are fine with me.
GalRogozinski
left a comment
There was a problem hiding this comment.
Changes will be handled in a different issue
Description
Replace all trit representations from int[] to byte[]
Currently, Trits (-1,0,1) are stored in integer arrays, which waste memory (and compute to GC).
This PR replaces all usage trit representations from
int[]tobyte[].Fixes #799
Type of change
How Has This Been Tested?
Checklist: