<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
                                        Wohoo! More tests. :-) Thanks. That thing about #withIndexDo: sounds reasonable.<div><br></div><div>+1</div><div><br></div><div>Best,</div><div>Marcel</div><div class="mb_sig"></div><blockquote class='history_container' type='cite' style='border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;'>
                        <p style='color: #AAAAAA; margin-top: 10px;'>Am 26.02.2022 22:19:42 schrieb christoph.thiede@student.hpi.uni-potsdam.de <christoph.thiede@student.hpi.uni-potsdam.de>:</p><div style='font-family:Arial,Helvetica,sans-serif'>
<b>=============== Summary ===============</b><br>
<br>
Change Set:        SparseLargeTable enumerate+tests<br>
Date:            26 February 2022<br>
Author:            Christoph Thiede<br>
<br>
This changeset makes two revisions two the enumerating protocol of SparseLargeTable and adds a few test for SparseLargeTable/SpargeLargeArray. Details:<br>
<br>
* Overrides #withIndexDo: to start from base index only<br>
* Adds #sparseElementsAndIndicesDo: for efficient iterating over all non-default values<br>
* Tests instance creation and enumeration for SparseLargeTable/SparseLargeArray<br>
<br>
<b>=============== Diff ===============</b><br>
<br>
<b>SparseLargeArrayTest</b><br>
<span style="color: #FF0000">+ SparseLargeTableTest subclass: #SparseLargeArrayTest<br>
+     instanceVariableNames: ''<br>
+     classVariableNames: ''<br>
+     poolDictionaries: ''<br>
+     category: 'CollectionsTests-Arrayed'<br>
+ <br>
+ SparseLargeArrayTest class <br>
+     instanceVariableNames: ''<br>
+ <br>
+ ""</span><br>
<br>
<b>SparseLargeArrayTest>>classUnderTest {accessing} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ classUnderTest<br>
+ <br>
+     ^ SparseLargeArray</span><br>
<br>
<b>SparseLargeArrayTest>>expectedFailures {accessing} · ct 2/26/2022 21:59</b><br>
<span style="color: #FF0000">+ expectedFailures<br>
+ <br>
+     ^ super expectedFailures ,<br>
+         #(testAccessing testSparseElementsAndIndicesDo) "SparseLargeArray(SparseLargeTable)>>zapDefaultOnlyEntries fails for last chunk"</span><br>
<br>
<b>SparseLargeArrayTest>>testAccessingWithoutZapping {testing - accessing} · ct 2/26/2022 21:57</b><br>
<span style="color: #FF0000">+ testAccessingWithoutZapping<br>
+ <br>
+     | size chunkSize indices table |<br>
+     size := 60.<br>
+     chunkSize := 8.<br>
+     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
+     table := self classUnderTest new: size chunkSize: chunkSize arrayClass: DoubleByteArray base: 11 defaultValue: 0.<br>
+     indices do: [:index |<br>
+         table at: index put: index squared].<br>
+     self shouldRaiseError: [table at: 40 put: 2 << 15].<br>
+     <br>
+     self assert: size equals: table size.<br>
+     self assert: chunkSize equals: table chunkSize.<br>
+     <br>
+     indices do: [:index |<br>
+         self assert: index squared equals: ((table at: index))].</span><br>
<br>
<b>SparseLargeArrayTest>>testSparseElementsAndIndicesDoWithoutZapping {testing - accessing} · ct 2/26/2022 21:59</b><br>
<span style="color: #FF0000">+ testSparseElementsAndIndicesDoWithoutZapping<br>
+ <br>
+     | defaultValue indices table sparse |<br>
+     defaultValue := 0.<br>
+     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
+     table := self classUnderTest new: 60 chunkSize: 8 arrayClass: DoubleByteArray base: 11 defaultValue: defaultValue.<br>
+     indices do: [:index |<br>
+         table at: index put: index squared].<br>
+     <br>
+     sparse := Dictionary new.<br>
+     table sparseElementsAndIndicesDo: [:element :index |<br>
+         self deny: (sparse includesKey: index).<br>
+         sparse at: index put: element].<br>
+     <br>
+     table withIndexDo: [:element :index |<br>
+         self assert: element equals: (sparse at: index ifAbsent: [0])].</span><br>
<br>
<b>SparseLargeTable>>sparseElementsAndIndicesDo: {accessing} · ct 2/26/2022 22:06</b><br>
<span style="color: #FF0000">+ sparseElementsAndIndicesDo: binaryBlock<br>
+     "Evaluate binaryBlock for each element and index in the receiver that has a non-default value."<br>
+ <br>
+     1 to: self basicSize do: [:chunkIndex |<br>
+         (self basicAt: chunkIndex) ifNotNil: [:chunk |<br>
+             chunk withIndexDo: [:element :innerIndex |<br>
+                 element ~= defaultValue ifTrue: [<br>
+                     binaryBlock value: element value: innerIndex + base - 1 + (chunkIndex - 1 * chunkSize)]]]].</span><br>
<br>
<b>SparseLargeTable>>withIndexDo: {enumerating} · ct 2/26/2022 22:02</b><br>
<span style="color: #FF0000">+ withIndexDo: binaryBlock<br>
+ <br>
+     self base to: self size do: [:index |<br>
+         binaryBlock<br>
+             value: (self at: index)<br>
+             value: index].</span><br>
<br>
<b>SparseLargeTableTest</b><br>
<span style="color: #FF0000">+ TestCase subclass: #SparseLargeTableTest<br>
+     instanceVariableNames: ''<br>
+     classVariableNames: ''<br>
+     poolDictionaries: ''<br>
+     category: 'CollectionsTests-Arrayed'<br>
+ <br>
+ SparseLargeTableTest class <br>
+     instanceVariableNames: ''<br>
+ <br>
+ ""</span><br>
<br>
<b>SparseLargeTableTest>>classUnderTest {accessing} · ct 2/26/2022 21:51</b><br>
<span style="color: #FF0000">+ classUnderTest<br>
+ <br>
+     ^ SparseLargeTable</span><br>
<br>
<b>SparseLargeTableTest>>testAccessing {tests - accessing} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ testAccessing<br>
+ <br>
+     | size chunkSize indices table |<br>
+     size := 60.<br>
+     chunkSize := 8.<br>
+     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
+     table := self classUnderTest new: size chunkSize: chunkSize arrayClass: DoubleByteArray base: 11 defaultValue: 0.<br>
+     indices do: [:index |<br>
+         table at: index put: index squared].<br>
+     self shouldRaiseError: [table at: 40 put: 2 << 15].<br>
+     table zapDefaultOnlyEntries.<br>
+     <br>
+     self assert: size equals: table size.<br>
+     self assert: chunkSize equals: table chunkSize.<br>
+     <br>
+     indices do: [:index |<br>
+         self assert: index squared equals: ((table at: index))].</span><br>
<br>
<b>SparseLargeTableTest>>testNew {tests - instance creation} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ testNew<br>
+     <br>
+     | table |<br>
+     table := self classUnderTest new.<br>
+     self assert: 0 equals: table size.</span><br>
<br>
<b>SparseLargeTableTest>>testNewFrom {tests - instance creation} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ testNewFrom<br>
+ <br>
+     | array table |<br>
+     array := Array streamContents: [:stream |<br>
+         15 timesRepeat: [stream nextPutAll: #($a $b $b $b $b $c $c $a)]]. "must be longer than defaultChunkSize"<br>
+     table := self classUnderTest newFrom: array.<br>
+     self assert: array size equals: table size.<br>
+     self assert: array equals: table asArray.</span><br>
<br>
<b>SparseLargeTableTest>>testNewWithAll {tests - instance creation} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ testNewWithAll<br>
+ <br>
+     | size table |<br>
+     size := 150. "must be longer than defaultChunkSize"<br>
+     table := self classUnderTest new: size withAll: 2.<br>
+     self assert: size equals: table size.<br>
+     self assert: (Array new: size withAll: 2) equals: table asArray.</span><br>
<br>
<b>SparseLargeTableTest>>testNewWithSize {tests - instance creation} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ testNewWithSize<br>
+ <br>
+     | size table |<br>
+     size := 14.<br>
+     table := self classUnderTest new: size chunkSize: 5.<br>
+     self assert: size equals: table size.<br>
+     1 to: size do: [:index | self assert: (table at: index) isNil].<br>
+     self shouldRaiseError: [table at: 0].<br>
+     self shouldRaiseError: [table at: size + 1].</span><br>
<br>
<b>SparseLargeTableTest>>testSparseElementsAndIndicesDo {tests - accessing} · ct 2/26/2022 21:52</b><br>
<span style="color: #FF0000">+ testSparseElementsAndIndicesDo<br>
+ <br>
+     | defaultValue indices table sparse |<br>
+     defaultValue := 0.<br>
+     indices := #(20 22 23 27 28 29 54 56 57 58).<br>
+     table := self classUnderTest new: 60 chunkSize: 8 arrayClass: DoubleByteArray base: 11 defaultValue: defaultValue.<br>
+     indices do: [:index |<br>
+         table at: index put: index squared].<br>
+     table zapDefaultOnlyEntries.<br>
+     <br>
+     sparse := Dictionary new.<br>
+     table sparseElementsAndIndicesDo: [:element :index |<br>
+         self deny: (sparse includesKey: index).<br>
+         sparse at: index put: element].<br>
+     <br>
+     table withIndexDo: [:element :index |<br>
+         self assert: element equals: (sparse at: index ifAbsent: [0])].</span><br>
<br>
<span style="color: #808080">---<br>
</span><span style="color: #808080"><i>Sent from </i></span><span style="color: #808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></span><br>
["SparseLargeTable enumerate+tests.1.cs"]
</div></blockquote>
                                        </div></body>