Advertisement
fruffl

Units ArraySegment

Mar 3rd, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.60 KB | None | 0 0
  1. <?PHP
  2. function writeArray($arrSeg)
  3. {
  4.     print "===\n";
  5.     print get_class($arrSeg)."\n";
  6.    
  7.     print ":\tArrIdx\toffset\tvalue\n";
  8.     print ":\t------\t------\t------\n";
  9.     foreach($arrSeg as $k => $v)
  10.         print ":\t".$arrSeg->peek($k)."\t".$k."\t".$v."\n";
  11. }
  12. function writeSeg($arrSeg)
  13. {
  14.     print "===\n";
  15.     print get_class($arrSeg).sprintf(' [start-index: %d|length: %d|last-index: %d]'."\n",
  16.         $arrSeg->getStart(),
  17.         $arrSeg->getLength(),
  18.         $arrSeg->getLast());
  19.    
  20.     print ":\tOffset\tSegIdx\tvalue\n";
  21.     print ":\t------\t------\t------\n";
  22.        
  23.     foreach($arrSeg as $k => $v)
  24.         print ":\t".$arrSeg->getReference()->peek($k)."\t".$k."\t".$v."\n";
  25. }
  26.  
  27. $a = new TAssoc(["The" => "quick", "brown" => "fox", "jumps" => "over", "the" => "lazy", "dog" => '.']);
  28.  
  29. $b = new TAssocSegment($a, 6, 5);   //"the", "lazy", "dog"
  30. $c = new TAssocSegment($a, NULL, 5);    //"The", "quick", "brown", "fox", "jumps"
  31. $d = new TAssocSegment($a, 1, NULL);    //"brown", "fox", "jumps", "over", "the"
  32. $e = new TAssocSegment($a, 2, 1);   //"brown", "fox", "jumps", "over", "the", "lazy", "dog"
  33.  
  34. $m = new TArray(["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", '.']);
  35.  
  36. $n = new TArraySegment($m, 6, 5);   //"the", "lazy", "dog"
  37. $o = new TArraySegment($m, NULL, 5);    //"The", "quick", "brown", "fox", "jumps"
  38. $p = new TArraySegment($m, 1, NULL);    //"brown", "fox", "jumps", "over", "the"
  39. $q = new TArraySegment($m, 2, 1);   //"brown", "fox", "jumps", "over", "the", "lazy", "dog"
  40.  
  41. print "\n\nDefaults\n";
  42. writeArray($a); //"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"
  43. writeArray($m);
  44.  
  45. print "\n\nTAssocSegment\n";
  46. writeSeg($b);
  47. writeSeg($c);
  48. writeSeg($d);
  49. writeSeg($e);   //"the", "lazy", "dog"
  50.  
  51. print "\n\nTArraySegment\n";
  52. writeSeg($n);
  53. writeSeg($o);
  54. writeSeg($p);
  55. writeSeg($q);
  56.  
  57. ?>
  58.  
  59.  
  60. Defaults
  61. ===
  62. ILLI\System\Collection\TAssoc
  63. :   ArrIdx  offset  value
  64. :   ------  ------  ------
  65. :   0   The quick
  66. :   1   brown   fox
  67. :   2   jumps   over
  68. :   3   the lazy
  69. :   4   dog .
  70. ===
  71. ILLI\System\Collection\TArray
  72. :   ArrIdx  offset  value
  73. :   ------  ------  ------
  74. :   0   0   The
  75. :   1   1   quick
  76. :   2   2   brown
  77. :   3   3   fox
  78. :   4   4   jumps
  79. :   5   5   over
  80. :   6   6   the
  81. :   7   7   lazy
  82. :   8   8   dog
  83. :   9   9   .
  84.  
  85.  
  86. TAssocSegment
  87. ===
  88. ILLI\System\Collection\TAssocSegment [start-index: 4|length: 5|last-index: 4]
  89. :   Offset  SegIdx  value
  90. :   ------  ------  ------
  91. :   dog 4   dog
  92. ===
  93. ILLI\System\Collection\TAssocSegment [start-index: 0|length: 5|last-index: 4]
  94. :   Offset  SegIdx  value
  95. :   ------  ------  ------
  96. :   The 0   The
  97. :   brown   1   brown
  98. :   jumps   2   jumps
  99. :   the 3   the
  100. :   dog 4   dog
  101. ===
  102. ILLI\System\Collection\TAssocSegment [start-index: 1|length: 0|last-index: 4]
  103. :   Offset  SegIdx  value
  104. :   ------  ------  ------
  105. :   brown   1   brown
  106. :   jumps   2   jumps
  107. :   the 3   the
  108. :   dog 4   dog
  109. ===
  110. ILLI\System\Collection\TAssocSegment [start-index: 2|length: 1|last-index: 2]
  111. :   Offset  SegIdx  value
  112. :   ------  ------  ------
  113. :   jumps   2   jumps
  114. :   the 3   the
  115. :   dog 4   dog
  116.  
  117.  
  118. TArraySegment
  119. ===
  120. ILLI\System\Collection\TArraySegment [start-index: 6|length: 5|last-index: 9]
  121. :   Offset  SegIdx  value
  122. :   ------  ------  ------
  123. :   6   6   the
  124. :   7   7   lazy
  125. :   8   8   dog
  126. :   9   9   .
  127. ===
  128. ILLI\System\Collection\TArraySegment [start-index: 0|length: 5|last-index: 4]
  129. :   Offset  SegIdx  value
  130. :   ------  ------  ------
  131. :   0   0   The
  132. :   1   1   quick
  133. :   2   2   brown
  134. :   3   3   fox
  135. :   4   4   jumps
  136. ===
  137. ILLI\System\Collection\TArraySegment [start-index: 1|length: 0|last-index: 9]
  138. :   Offset  SegIdx  value
  139. :   ------  ------  ------
  140. :   1   1   quick
  141. :   2   2   brown
  142. :   3   3   fox
  143. :   4   4   jumps
  144. :   5   5   over
  145. :   6   6   the
  146. :   7   7   lazy
  147. :   8   8   dog
  148. :   9   9   .
  149. ===
  150. ILLI\System\Collection\TArraySegment [start-index: 2|length: 1|last-index: 2]
  151. :   Offset  SegIdx  value
  152. :   ------  ------  ------
  153. :   2   2   brown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement