Changeset 2178
- Timestamp:
- 07/03/08 13:58:11 (3 months ago)
- Files:
-
- trunk/Library/FortressLibrary.fsi (modified) (8 diffs)
- trunk/Library/FortressLibrary.fss (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Library/FortressLibrary.fsi
r2164 r2178 954 954 be either mutable or immutable. *) 955 955 trait ReadableArray[\E,I\] 956 extends { HasRank, Indexed[\E,I\] }956 extends { HasRank, Indexed[\E,I\], DelegatedIndexed[\E,I\] } 957 957 comprises { Array[\E,I\], ImmutableArray[\E,I\] } 958 958 (** CONCRETE GETTERS 959 Default implementations of getters based on abstract methods 960 below. **) 961 getter indices(): Indexed[\I,I\] 962 getter indexValuePairs(): Indexed[\(I,E),I\] 963 getter generator(): Indexed[\E,I\] 964 965 (** CONCRETE METHODS 966 Default implementations of most array stuff based on the above. 967 The things we can't provide are anything involving replica. **) 968 969 opr[i:I]:E 970 971 (** Initialize element at index i with value v. This should occur 972 once, before any other access or assignment occurs to element 973 i. An error will be signaled if an uninitialized element is 974 read or an initialized element is re-initialized. **) 975 init(i:I, v:E) 976 977 generate[\R\](r: Reduction[\R\], body: E->R): R 978 seq(self): SequentialGenerator[\E\] 979 980 (** 0-based non-bounds-checked indexing. **) 981 abstract get(i:I): E 982 abstract init0(i:I, e:E): () 983 abstract zeroIndices(): FullRange[\I\] 984 (** Convert from %base%-based indexing to 0-based indexing, 985 performing bounds checking. **) 986 abstract offset(i:I): I 987 (** Convert from 0-based indexing to %base%-based indexing. **) 988 abstract toIndex(i:I): I 959 989 (** Indexed functionality with more specific type information. **) 960 990 abstract opr[r:Range[\I\]] : ReadableArray[\E,I\] … … 968 998 abstract shift(newOrigin:I):ReadableArray[\E,I\] 969 999 970 (** Initialize element at index %i% with value %v%. This should occur 971 once, before any other access or assignment occurs to element 972 %i%. An error will be signaled if an uninitialized element is 973 read or an initialized element is re-initialized. **) 974 abstract init(i:I, v:E): () 975 976 (** Bulk initialization of an array using a given function or value. **) 1000 (** Bulk initialization of an array using a given function or 1001 value. These are defined with more specific self types in 1002 StandardImmutableArrayType. **) 977 1003 abstract fill(f:I->E):ReadableArray[\E,I\] 978 1004 abstract fill(v:E):ReadableArray[\E,I\] … … 994 1020 abstract map[\R\](f:E->R): ImmutableArray[\R, I\] 995 1021 abstract shift(newOrigin:I):ImmutableArray[\E,I\] 996 abstract init(i:I, v:E): ()997 1022 abstract fill(f:I->E):ImmutableArray[\E,I\] 998 1023 abstract fill(v:E):ImmutableArray[\E,I\] … … 1005 1030 1006 1031 trait Array[\E,I\] extends { ReadableArray[\E,I\], MutableIndexed[\E,I\] } 1032 abstract put(i:I, e:E): () 1033 opr[i:I]:=(v:E):() 1034 1035 opr[r:Range[\I\]]:=(a:Indexed[\E,I\]):() 1036 1007 1037 abstract opr[r:Range[\I\]] : Array[\E,I\] 1008 1038 abstract opr[_:OpenRange[\Any\]] : Array[\E,I\] … … 1010 1040 abstract map[\R\](f:E->R): Array[\R, I\] 1011 1041 abstract shift(newOrigin:I):Array[\E,I\] 1012 abstract init(i:I, v:E): ()1013 1042 abstract fill(f:I->E):Array[\E,I\] 1014 1043 abstract fill(v:E):Array[\E,I\] … … 1037 1066 primitiveImmutableArray[\E\](x:ZZ32):ImmutableArray[\E,ZZ32\] 1038 1067 1039 (** Array type supporting un-bounds-checked 0-based indexing.1040 Useful for the internals of all the array functionality. **)1041 trait ArrayTypeWith0[\E,I\]1042 extends { ReadableArray[\E,I\], DelegatedIndexed[\E,I\] }1043 (** 0-based non-bounds-checked indexing. **)1044 abstract getDefault(i:I): E1045 abstract init0(i:I, e:E): ()1046 abstract zeroIndices(): FullRange[\I\]1047 (** Convert from %base%-based indexing to 0-based indexing,1048 performing bounds checking. **)1049 abstract offset(i:I): I1050 (** Convert from 0-based indexing to %base%-based indexing. **)1051 abstract toIndex(i:I): I1052 end1053 1054 1068 (** NOTE: %StandardImmutableArrayType% is a parent of 1055 1069 %StandardMutableArrayType%. It therefore does not extend 1056 %ImmutableArray Type% as you might expect. Other types that extend1057 it should also extend %ImmutableArray Type% explicitly. **)1070 %ImmutableArray% as you might expect. Other types that extend 1071 it should also extend %ImmutableArray% explicitly. **) 1058 1072 trait StandardImmutableArrayType[\T extends StandardImmutableArrayType[\T,E,I\],E,I\] 1059 extends { ArrayTypeWith0[\E,I\] } 1060 (** CONCRETE GETTERS: 1061 Default implementations of getters based on abstract methods 1062 in %StandardArrayType%. **) 1063 getter indices(): Indexed[\I,I\] 1064 getter indexValuePairs(): Indexed[\(I,E),I\] 1065 getter generator(): Indexed[\E,I\] 1066 1067 (** CONCRETE METHODS: 1068 Default implementations of most array stuff based on the above. 1069 The things we cannot provide are anything involving replica. **) 1070 opr[i:I]:E 1071 init(i:I, v:E) 1072 1073 generate[\R\](r: Reduction[\R\], body: E->R): R 1074 seq(self): SequentialGenerator[\E\] 1075 1073 extends { ReadableArray[\E,I\] } 1076 1074 fill(f:I->E):T 1077 1075 fill(v:E):T … … 1081 1079 1082 1080 trait StandardMutableArrayType[\T extends StandardMutableArrayType[\T,E,I\],E,I\] 1083 extends { StandardImmutableArrayType[\T,E,I\], Array[\E,I\] } 1084 (** 0-based non-bounds-checked indexing. **) 1085 abstract put(i:I, e:E): () 1086 opr[i:I]:=(v:E):() 1087 1088 opr[r:Range[\I\]]:=(a:Indexed[\E,I\]):() 1089 1081 extends { StandardImmutableArrayType[\T,E,I\], Array[\E,I\] } 1090 1082 assign(v:T):T 1091 1083 assign(f:I->E):T … … 1106 1098 %b0+s0-1%. **) 1107 1099 trait ReadableArray1[\T, nat b0, nat s0\] 1108 extends { Indexed1[\s0\], Rank1, ArrayTypeWith0[\T,ZZ32\] }1100 extends { Indexed1[\s0\], Rank1, ReadableArray[\T,ZZ32\] } 1109 1101 comprises { ImmutableArray1[\T,b0,s0\], Array1[\T,b0,s0\] } 1110 1102 getter size():ZZ32 trunk/Library/FortressLibrary.fss
r2172 r2178 1311 1311 be either mutable or immutable. *) 1312 1312 trait ReadableArray[\E,I\] 1313 extends { HasRank, Indexed[\E,I\] }1313 extends { HasRank, Indexed[\E,I\], DelegatedIndexed[\E,I\] } 1314 1314 comprises { Array[\E,I\], ImmutableArray[\E,I\] } 1315 (** CONCRETE GETTERS 1316 Default implementations of getters based on abstract methods 1317 below. **) 1318 getter indices(): Indexed[\I,I\] = bounds() 1319 getter indexValuePairs(): Indexed[\(I,E),I\] = 1320 zeroIndices().map[\(I,E)\](fn (i:I):(I,E) => (toIndex(i),get(i))) 1321 getter generator(): Indexed[\E,I\] = 1322 zeroIndices().map[\E\](fn (i:I):E => get(i)) 1323 1324 (** CONCRETE METHODS 1325 Default implementations of most array stuff based on the above. 1326 The things we can't provide are anything involving replica. **) 1327 1328 opr[i:I]:E = get(offset(i)) 1329 1330 (** Initialize element at index i with value v. This should occur 1331 once, before any other access or assignment occurs to element 1332 i. An error will be signaled if an uninitialized element is 1333 read or an initialized element is re-initialized. **) 1334 init(i:I, v:E) = init0(offset(i),v) 1335 1336 generate[\R\](r: Reduction[\R\], body: E->R): R = 1337 generator().generate[\R\](r,body) 1338 seq(self): SequentialGenerator[\E\] = seq(generator()) 1339 1340 (** 0-based non-bounds-checked indexing **) 1341 get(i:I): E 1342 init0(i:I, e:E): () 1343 zeroIndices(): FullRange[\I\] 1344 (** Convert from base()-based indexing to 0-based indexing, 1345 performing bounds checking. **) 1346 offset(i:I): I 1347 (** Convert from 0-based indexing to base()-based indexing **) 1348 toIndex(i:I): I 1315 1349 1316 1350 (** Indexed functionality with more specific type information **) … … 1325 1359 shift(newOrigin:I):ReadableArray[\E,I\] 1326 1360 1327 (** Initialize element at index i with value v. This should occur 1328 once, before any other access or assignment occurs to element 1329 i. An error will be signaled if an uninitialized element is 1330 read or an initialized element is re-initialized. **) 1331 init(i:I, v:E): () 1332 1333 (** Bulk initialization of an array using a given function or value **) 1361 (** Bulk initialization of an array using a given function or 1362 value. These are defined with more specific self types in 1363 StandardImmutableArrayType. **) 1334 1364 fill(f:I->E):ReadableArray[\E,I\] 1335 1365 fill(v:E):ReadableArray[\E,I\] … … 1357 1387 map[\R\](f:E->R): ImmutableArray[\R, I\] 1358 1388 shift(newOrigin:I):ImmutableArray[\E,I\] 1359 init(i:I, v:E): ()1360 1389 fill(f:I->E):ImmutableArray[\E,I\] 1361 1390 fill(v:E):ImmutableArray[\E,I\] … … 1368 1397 1369 1398 trait Array[\E,I\] extends { ReadableArray[\E,I\], MutableIndexed[\E,I\] } 1399 (** 0-based non-bounds-checked indexing **) 1400 put(i:I, e:E): () 1401 opr[i:I]:=(v:E):() = put(offset(i),v) 1402 1403 opr[r:Range[\I\]]:=(a:Indexed[\E,I\]):() = do 1404 a0 = a[a.bounds()] (* Make a have 0 origin *) 1405 s0 = self[r] (* Make self have 0 origin *) 1406 if a0.bounds() = s0.bounds() then 1407 for (i,v) <- a0.indexValuePairs() do 1408 s0.put(i,v) 1409 end 1410 else 1411 fail("Can't assign indexed with bounds " a.bounds() // 1412 " to differently-sized subarray " self.bounds()) 1413 end 1414 end 1415 1416 (** The following are repetition with better return type info. **) 1370 1417 opr[r:Range[\I\]] : Array[\E,I\] 1371 1418 opr[_:OpenRange[\Any\]] : Array[\E,I\] … … 1373 1420 map[\R\](f:E->R): Array[\R, I\] 1374 1421 shift(newOrigin:I):Array[\E,I\] 1375 init(i:I, v:E): ()1376 1422 fill(f:I->E):Array[\E,I\] 1377 1423 fill(v:E):Array[\E,I\] … … 1432 1478 PrimImmutableArray[\E,n\]() 1433 1479 1434 (** Array type supporting un-bounds-checked 0-based indexing.1435 Useful for the internals of all the array functionality. **)1436 trait ArrayTypeWith0[\E,I\]1437 extends { ReadableArray[\E,I\], DelegatedIndexed[\E,I\] }1438 (** 0-based non-bounds-checked indexing **)1439 get(i:I): E1440 init0(i:I, e:E): ()1441 zeroIndices(): FullRange[\I\]1442 (** Convert from base()-based indexing to 0-based indexing,1443 performing bounds checking. **)1444 offset(i:I): I1445 (** Convert from 0-based indexing to base()-based indexing **)1446 toIndex(i:I): I1447 end1448 1449 1480 (** NOTE: StandardImmutableArrayType is a parent of 1450 1481 StandardMutableArrayType. It therefore doesn't extend 1451 ImmutableArray Typeas you might expect. Other types that extend1452 it should also extend ImmutableArray Typeexplicitly. **)1482 ImmutableArray as you might expect. Other types that extend 1483 it should also extend ImmutableArray explicitly. **) 1453 1484 trait StandardImmutableArrayType[\T extends StandardImmutableArrayType[\T,E,I\],E,I\] 1454 extends { ArrayTypeWith0[\E,I\] } 1455 (** CONCRETE GETTERS 1456 Default implementations of getters based on abstract methods 1457 in StandardArrayType. **) 1458 getter indices(): Indexed[\I,I\] = bounds() 1459 getter indexValuePairs(): Indexed[\(I,E),I\] = 1460 zeroIndices().map[\(I,E)\](fn (i:I):(I,E) => (toIndex(i),get(i))) 1461 getter generator(): Indexed[\E,I\] = 1462 zeroIndices().map[\E\](fn (i:I):E => get(i)) 1463 1464 (** CONCRETE METHODS 1465 Default implementations of most array stuff based on the above. 1466 The things we can't provide are anything involving replica. **) 1467 opr[i:I]:E = get(offset(i)) 1468 init(i:I, v:E) = init0(offset(i),v) 1469 1470 generate[\R\](r: Reduction[\R\], body: E->R): R = 1471 generator().generate[\R\](r,body) 1472 seq(self): SequentialGenerator[\E\] = seq(generator()) 1473 1485 extends { ReadableArray[\E,I\] } 1474 1486 fill(f:I->E):T = do 1475 1487 for i <- zeroIndices() do init0(i,f(toIndex(i))) end … … 1486 1498 1487 1499 trait StandardMutableArrayType[\T extends StandardMutableArrayType[\T,E,I\],E,I\] 1488 extends { StandardImmutableArrayType[\T,E,I\], Array[\E,I\] } 1489 (** 0-based non-bounds-checked indexing **) 1490 put(i:I, e:E): () 1491 opr[i:I]:=(v:E):() = put(offset(i),v) 1492 1493 opr[r:Range[\I\]]:=(a:Indexed[\E,I\]):() = do 1494 a0 = a[a.bounds()] (* Make a have 0 origin *) 1495 s0 = self[r] (* Make self have 0 origin *) 1496 if a0.bounds() = s0.bounds() then 1497 for (i,v) <- a.indexValuePairs() do 1498 s0.put(i,v) 1499 end 1500 else 1501 fail("Can't assign indexed with bounds " a.bounds() // 1502 " to differently-sized subarray " self.bounds()) 1503 end 1504 end 1505 1500 extends { StandardImmutableArrayType[\T,E,I\], Array[\E,I\] } 1506 1501 assign(v:T):T = do 1507 1502 for i <- zeroIndices() do put(i,v.get(i)) end … … 1529 1524 The natural order of all generators is from b0 to b0+s0-1. **) 1530 1525 trait ReadableArray1[\T, nat b0, nat s0\] 1531 extends { Indexed1[\s0\], Rank1, ArrayTypeWith0[\T,ZZ32\] }1526 extends { Indexed1[\s0\], Rank1, ReadableArray[\T,ZZ32\] } 1532 1527 comprises { ImmutableArray1[\T,b0,s0\], Array1[\T,b0,s0\] } 1533 1528 getter size():ZZ32 = s0
