Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I loop into the ArrayList's Block's Tuple?
    text
    copied!<p>I am sorry if the code is long. <strong>Block</strong> and <strong>Tuple</strong> are self defined classes. Their attributes are protected. <strong>Block</strong> contains a <strong>ArrayList</strong> of <strong>Tuples</strong>. <strong>Tuple</strong> has attribute int <strong>Key</strong> and String <strong>value</strong></p> <p>I have ArrayList[] bucketLstS and Block[] bucketBlocksS</p> <pre><code>ArrayList[] bucketLstS = new ArrayList[Setting.memorySize - 1]; Block[] bucketBlocksS = new Block[Setting.memorySize - 1]; for (int i = 0; i &lt; bucketBlocksS.length; i++) { bucketLstS[i] = new ArrayList&lt;Tuple&gt;(); bucketBlocksS[i] = new Block(); } //Get individual relS keys RelationLoader sLoader = relS.getRelationLoader(); while (sLoader.hasNext()) { Block[] blocks = sLoader.loadNextBlocks(1); for (Block b : blocks) { numIO++; if (b != null) { for (Tuple t : b.tupleLst) { //Hash the key to determine which Bucket bucketIdx = t.key % (Setting.memorySize - 2); //System.out.println(bucketBlocksS[bucketIdx].getNumTuples()); //check if the block is already full if (bucketBlocksS[bucketIdx].getNumTuples() &gt;= Setting.blockFactor) { bucketLstS[bucketIdx].add(bucketBlocksS[bucketIdx]); bucketBlocksS[bucketIdx] = new Block(); blkNum++; } bucketBlocksS[bucketIdx].insertTuple(t); } } } }//end while </code></pre> <p>The question is that I need to loop into each Block, so that I can access each Tuple's <strong>Key</strong> and <strong>value</strong> I tried this:</p> <pre><code> for (int i = 0; i &lt; bucketLstS.length; i++) { System.out.println(i + " " + bucketLstS[i]); for (int j = 0; j &lt; bucketLstS[i].size(); j++) { //Access a Block in Block Array System.out.println(j + " " + bucketLstS[i].get(j)); } } </code></pre> <p>But then I am stuck. The output is like:</p> <pre><code>0 [project2.Block@558fee4f, project2.Block@5c66b06b, project2.Block@59c87031, project2.Block@763dcf03, project2.Block@53e20a9a, project2.Block@1d262f7c, project2.Block@35f784d7, project2.Block@d325aef, project2.Block@64f007ad] 0 project2.Block@558fee4f 1 project2.Block@5c66b06b 2 project2.Block@59c87031 3 project2.Block@763dcf03 4 project2.Block@53e20a9a 5 project2.Block@1d262f7c 6 project2.Block@35f784d7 7 project2.Block@d325aef 8 project2.Block@64f007ad </code></pre> <p>But how to I get into the Tuple of a Block to get to the key? (To obtain key, can use Tuple.key)</p> <p>Following is the Class for Block</p> <pre><code>import java.util.ArrayList; public class Block { /** * List of tuples contained in this block */ protected ArrayList&lt;Tuple&gt; tupleLst; public Block(){ this.tupleLst=new ArrayList&lt;Tuple&gt;(Setting.blockFactor); } /** * Insert a tuple t to this block * @param t is a tuple to be inserted to this block * @return true if tuple t is successfully inserted into this block and false if the block is full */ //One tupleLst can store up to "10" tuples public boolean insertTuple(Tuple t){ if(tupleLst.size()&lt;Setting.blockFactor){ tupleLst.add(t); return true; } return false; } /** * @return number of tuples stored in this block */ public int getNumTuples(){ return tupleLst.size(); } /** * Print this block * @param printTuple is a flag to indicate whether the details of the tuples are printed */ public void print(boolean printTuple){ System.out.println("[BlockSize: "+getNumTuples()+"]"); if(printTuple){ for(Tuple t:tupleLst){ System.out.println(t); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload