Changeset 15397
- Timestamp:
- 2013-02-28T19:11:04+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Util/List.mo
r15249 r15397 1151 1151 end uniqueIntN_work; 1152 1152 1153 public function uniqueIntNArr 1154 "Takes a list of integes and returns a list with duplicates removed, so that 1155 each element in the new list is unique. O(listLength(inList)). The function 1156 also takes an array of Integer of size N+1 to mark the already selected entries <= N. 1157 The last entrie of the array is used for the mark index. It will be updated after 1158 each call" 1159 input list<Integer> inList; 1160 input array<Integer> markarr; 1161 input list<Integer> iAcc; 1162 output list<Integer> oAcc; 1163 algorithm 1164 oAcc := matchcontinue(inList,markarr,iAcc) 1165 local 1166 Integer i,len,mark; 1167 list<Integer> ilst,acc; 1168 case ({},_,_) 1169 equation 1170 len = arrayLength(markarr); 1171 _=arrayUpdate(markarr,len,markarr[len]+1); 1172 then iAcc; 1173 case (i::ilst,_,_) 1174 equation 1175 len = arrayLength(markarr); 1176 true = intLt(i,len); 1177 mark = markarr[len]; 1178 acc = consOnTrue(intNe(markarr[i],mark),i,iAcc); 1179 _=arrayUpdate(markarr,i,mark); 1180 then 1181 uniqueIntNArr(ilst,markarr,acc); 1182 else 1183 equation 1184 print("List.uniqueIntNArr failed entrie to large\n"); 1185 then 1186 fail(); 1187 end matchcontinue; 1188 end uniqueIntNArr; 1189 1153 1190 public function uniqueOnTrue 1154 1191 "Takes a list of elements and a comparison function over two elements of the … … 5411 5448 public function flatten 5412 5449 "Takes a list of lists and flattens it out, producing one list of all elements 5413 of the sublists. 5450 of the sublists. O(len(outList)) 5414 5451 Example: flatten({{1, 2}, {3, 4, 5}, {6}, {}}) => {1, 2, 3, 4, 5, 6}" 5415 5452 input list<list<ElementType>> inList; 5416 5453 output list<ElementType> outList; 5417 5454 algorithm 5418 outList := flatten_tail( inList, {});5455 outList := flatten_tail(listReverse(inList), {}); 5419 5456 end flatten; 5420 5457 … … 5433 5470 case (e :: rest, _) 5434 5471 equation 5435 res = listAppend( inAccumList, e);5472 res = listAppend(e,inAccumList); 5436 5473 then 5437 5474 flatten_tail(rest, res);
Note: See TracChangeset
for help on using the changeset viewer.