Changeset 2415 for trunk/sources/LibSVM/Cache.cs
- Timestamp:
- 10/07/09 11:58:21 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/LibSVM/Cache.cs
r1819 r2415 49 49 private head_t lru_head; 50 50 51 internalCache(int count, long size)51 public Cache(int count, long size) 52 52 { 53 53 _count = count; … … 78 78 } 79 79 80 private static void swap<T>(ref T lhs, ref T rhs) 81 { 82 T tmp = lhs; 83 lhs = rhs; 84 rhs = tmp; 85 } 86 80 87 // request data [0,len) 81 88 // return some position p where [p,len) need to be filled 82 89 // (p >= len if nothing needs to be filled) 83 90 // java: simulate pointer using single-element array 84 internal virtual int get_data(int index, float[][] data, int len)91 public int GetData(int index, ref float[] data, int len) 85 92 { 86 93 head_t h = head[index]; … … 107 114 h.data = new_data; 108 115 _size -= more; 109 do 110 { 111 int _ = h.len; h.len = len; len = _; 112 } 113 while (false); 116 swap(ref h.len, ref len); 114 117 } 115 118 116 119 lru_insert(h); 117 data [0]= h.data;120 data = h.data; 118 121 return len; 119 122 } 120 123 121 internal virtual void swap_index(int i, int j)124 public void SwapIndex(int i, int j) 122 125 { 123 126 if (i == j) … … 128 131 if (head[j].len > 0) 129 132 lru_delete(head[j]); 130 do 131 { 132 float[] _ = head[i].data; head[i].data = head[j].data; head[j].data = _; 133 } 134 while (false); 135 do 136 { 137 int _ = head[i].len; head[i].len = head[j].len; head[j].len = _; 138 } 139 while (false); 133 swap(ref head[i].data, ref head[j].data); 134 swap(ref head[i].len, ref head[j].len); 140 135 if (head[i].len > 0) 141 136 lru_insert(head[i]); … … 144 139 145 140 if (i > j) 146 do 147 { 148 int _ = i; i = j; j = _; 149 } 150 while (false); 141 swap(ref i, ref j); 142 151 143 for (head_t h = lru_head.next; h != lru_head; h = h.next) 152 144 { … … 154 146 { 155 147 if (h.len > j) 156 do 157 { 158 float _ = h.data[i]; h.data[i] = h.data[j]; h.data[j] = _; 159 } 160 while (false); 148 swap(ref h.data[i], ref h.data[j]); 161 149 else 162 150 {
Note: See TracChangeset
for help on using the changeset viewer.