corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * CVS identifier:
3 *
4 * $Id: ArrayUtil.java,v 1.10 2000/09/05 09:25:15 grosbois Exp $
5 *
6 * Class: ArrayUtil
7 *
8 * Description: Utillities for arrays.
9 *
10 *
11 *
12 * COPYRIGHT:
13 *
14 * This software module was originally developed by Raphaël Grosbois and
15 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel
16 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David
17 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research
18 * Centre France S.A) in the course of development of the JPEG2000
19 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This
20 * software module is an implementation of a part of the JPEG 2000
21 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio
22 * Systems AB and Canon Research Centre France S.A (collectively JJ2000
23 * Partners) agree not to assert against ISO/IEC and users of the JPEG
24 * 2000 Standard (Users) any of their rights under the copyright, not
25 * including other intellectual property rights, for this software module
26 * with respect to the usage by ISO/IEC and Users of this software module
27 * or modifications thereof for use in hardware or software products
28 * claiming conformance to the JPEG 2000 Standard. Those intending to use
29 * this software module in hardware or software products are advised that
30 * their use may infringe existing patents. The original developers of
31 * this software module, JJ2000 Partners and ISO/IEC assume no liability
32 * for use of this software module or modifications thereof. No license
33 * or right to this software module is granted for non JPEG 2000 Standard
34 * conforming products. JJ2000 Partners have full right to use this
35 * software module for his/her own purpose, assign or donate this
36 * software module to any third party and to inhibit third parties from
37 * using this software module for non JPEG 2000 Standard conforming
38 * products. This copyright notice must be included in all copies or
39 * derivative works of this software module.
40 *
41 * Copyright (c) 1999/2000 JJ2000 Partners.
42 *
43 *
44 *
45 */
46 using System;
47 namespace CSJ2K.j2k.util
48 {
49  
50 /// <summary> This class contains a colleaction of utility static methods for arrays.
51 ///
52 /// </summary>
53 public class ArrayUtil
54 {
55  
56 /// <summary>The maximum array size to do element by element copying, larger
57 /// arrays are copyied in a n optimized way.
58 /// </summary>
59 public const int MAX_EL_COPYING = 8;
60  
61 /// <summary>The number of elements to copy initially in an optimized array copy </summary>
62 public const int INIT_EL_COPYING = 4;
63  
64 /// <summary> Reinitializes an int array to the given value in an optimized way. If
65 /// the length of the array is less than MAX_EL_COPYING, then the array
66 /// is set element by element in the normal way, otherwise the first
67 /// INIT_EL_COPYING elements are set element by element and then
68 /// System.arraycopy is used to set the other parts of the array.
69 ///
70 /// </summary>
71 /// <param name="arr">The array to set.
72 ///
73 /// </param>
74 /// <param name="val">The value to set the array to.
75 ///
76 ///
77 ///
78 /// </param>
79 public static void intArraySet(int[] arr, int val)
80 {
81 int i, len, len2;
82  
83 len = arr.Length;
84 // Set array to 'val' in an optimized way
85 if (len < MAX_EL_COPYING)
86 {
87 // Not worth doing optimized way
88 for (i = len - 1; i >= 0; i--)
89 {
90 // Set elements
91 arr[i] = val;
92 }
93 }
94 else
95 {
96 // Do in optimized way
97 len2 = len >> 1;
98 for (i = 0; i < INIT_EL_COPYING; i++)
99 {
100 // Set first elements
101 arr[i] = val;
102 }
103 for (; i <= len2; i <<= 1)
104 {
105 // Copy values doubling size each time
106 Array.Copy(arr, 0, arr, i, i);
107 }
108 if (i < len)
109 {
110 // Copy values to end
111 Array.Copy(arr, 0, arr, i, len - i);
112 }
113 }
114 }
115  
116 /// <summary> Reinitializes a byte array to the given value in an optimized way. If
117 /// the length of the array is less than MAX_EL_COPYING, then the array
118 /// is set element by element in the normal way, otherwise the first
119 /// INIT_EL_COPYING elements are set element by element and then
120 /// System.arraycopy is used to set the other parts of the array.
121 ///
122 /// </summary>
123 /// <param name="arr">The array to set.
124 ///
125 /// </param>
126 /// <param name="val">The value to set the array to.
127 ///
128 ///
129 ///
130 /// </param>
131 public static void byteArraySet(byte[] arr, byte val)
132 {
133 int i, len, len2;
134  
135 len = arr.Length;
136 // Set array to 'val' in an optimized way
137 if (len < MAX_EL_COPYING)
138 {
139 // Not worth doing optimized way
140 for (i = len - 1; i >= 0; i--)
141 {
142 // Set elements
143 arr[i] = val;
144 }
145 }
146 else
147 {
148 // Do in optimized way
149 len2 = len >> 1;
150 for (i = 0; i < INIT_EL_COPYING; i++)
151 {
152 // Set first elements
153 arr[i] = val;
154 }
155 for (; i <= len2; i <<= 1)
156 {
157 // Copy values doubling size each time
158 Array.Copy(arr, 0, arr, i, i);
159 }
160 if (i < len)
161 {
162 // Copy values to end
163 Array.Copy(arr, 0, arr, i, len - i);
164 }
165 }
166 }
167 }
168 }