1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
|
//# ExprNodeSet.cc: Classes representing a set in table select expression
//# Copyright (C) 1997,1999,2000,2001,2003
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id: ExprNodeSet.cc 21262 2012-09-07 12:38:36Z gervandiepen $
#include <casacore/tables/TaQL/ExprNodeSet.h>
#include <casacore/tables/TaQL/ExprNode.h>
#include <casacore/tables/TaQL/ExprUnitNode.h>
#include <casacore/tables/TaQL/ExprDerNode.h>
#include <casacore/tables/TaQL/ExprDerNodeArray.h>
#include <casacore/tables/Tables/TableError.h>
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/IO/ArrayIO.h>
#include <casacore/casa/Arrays/IPosition.h>
#include <casacore/casa/Arrays/Slicer.h>
#include <casacore/casa/BasicMath/Math.h>
#include <casacore/casa/Utilities/GenSort.h>
#include <casacore/casa/Utilities/Assert.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
TableExprNodeSetElem::TableExprNodeSetElem (const TableExprNode& value)
: TableExprNodeRep (NTDouble, VTSetElem, OtUndef, Table()),
itsStart (0),
itsEnd (0),
itsIncr (0),
itsEndExcl (False),
itsLeftClosed (True),
itsRightClosed (True),
itsDiscrete (True),
itsSingle (True)
{
itsStart = value.getRep();
dtype_p = itsStart->dataType();
setUnit (itsStart->unit());
checkTable();
}
TableExprNodeSetElem::TableExprNodeSetElem (const TableExprNode* start,
const TableExprNode* end,
const TableExprNode* incr,
Bool isEndExcl)
: TableExprNodeRep (NTDouble, VTSetElem, OtUndef, Table()),
itsStart (0),
itsEnd (0),
itsIncr (0),
itsEndExcl (isEndExcl),
itsLeftClosed (True),
itsRightClosed (True),
itsDiscrete (True),
itsSingle (False)
{
// Link to the nodes and determine the data types.
//# Note that the TableExprNode copy ctor is needed to get rid of const.
Bool isScalar = True;
NodeDataType dts = NTInt;
if (start) {
itsStart = start->getRep();
dts = itsStart->dataType();
isScalar = isScalar && start->isScalar();
}
NodeDataType dte = dts;
if (end) {
itsEnd = end->getRep();
dte = itsEnd->dataType();
isScalar = isScalar && end->isScalar();
}
NodeDataType dti = NTInt;
if (incr) {
itsIncr = incr->getRep();
dti = itsIncr->dataType();
isScalar = isScalar && incr->isScalar();
}
if (!isScalar) {
throw TableInvExpr("Scalar values must be used in start:incr:end");
}
if (dts == NTInt && (dte == NTDouble || dti == NTDouble)) dts = NTDouble;
if (dte == NTInt && (dts == NTDouble || dti == NTDouble)) dte = NTDouble;
if ((dts != NTInt && dts != NTDouble && dts != NTDate)
|| dte != dts || (dti != NTInt && dti != NTDouble)) {
throw TableInvExpr("start:end should have equal data types (Int, Double"
" or Date) and incr should have Int or Double");
}
// Find unit and adapt units if needed.
setUnit (TableExprNodeUnit::adaptUnits (itsStart, itsEnd, itsIncr));
dtype_p = dts;
checkTable();
}
TableExprNodeSetElem::TableExprNodeSetElem (Bool isLeftClosed,
const TableExprNode& start,
const TableExprNode& end,
Bool isRightClosed)
: TableExprNodeRep (NTDouble, VTSetElem, OtUndef, Table())
{
setup (isLeftClosed, &start, &end, isRightClosed);
}
TableExprNodeSetElem::TableExprNodeSetElem (Bool isLeftClosed,
const TableExprNode& start)
: TableExprNodeRep (NTDouble, VTSetElem, OtUndef, Table())
{
setup (isLeftClosed, &start, 0, False);
}
TableExprNodeSetElem::TableExprNodeSetElem (const TableExprNode& end,
Bool isRightClosed)
: TableExprNodeRep (NTDouble, VTSetElem, OtUndef, Table())
{
setup (False, 0, &end, isRightClosed);
}
TableExprNodeSetElem::TableExprNodeSetElem (const TableExprNodeSetElem& that)
: TableExprNodeRep (that),
itsStart (that.itsStart),
itsEnd (that.itsEnd),
itsIncr (that.itsIncr),
itsEndExcl (that.itsEndExcl),
itsLeftClosed (that.itsLeftClosed),
itsRightClosed (that.itsRightClosed),
itsDiscrete (that.itsDiscrete),
itsSingle (that.itsSingle)
{}
TableExprNodeSetElem::TableExprNodeSetElem (const TableExprNodeSetElem& that,
const TENShPtr& start,
const TENShPtr& end,
const TENShPtr& incr)
: TableExprNodeRep (that.dataType(), VTSetElem, OtUndef, Table()),
itsStart (start),
itsEnd (end),
itsIncr (incr),
itsEndExcl (that.itsEndExcl),
itsLeftClosed (that.itsLeftClosed),
itsRightClosed (that.itsRightClosed),
itsDiscrete (that.itsDiscrete),
itsSingle (that.itsSingle)
{
TableExprNodeUnit::adaptUnits (itsStart, itsEnd, itsIncr);
}
TableExprNodeSetElem::~TableExprNodeSetElem()
{}
void TableExprNodeSetElem::setup (Bool isLeftClosed,
const TableExprNode* start,
const TableExprNode* end,
Bool isRightClosed)
{
itsStart = 0;
itsEnd = 0;
itsIncr = 0;
itsEndExcl = False;
itsLeftClosed = isLeftClosed;
itsRightClosed = isRightClosed;
itsDiscrete = False;
itsSingle = False;
Bool isScalar = True;
//# Note that the TableExprNode copy ctor is needed to get rid of const.
if (start) {
itsStart = start->getRep();
isScalar = isScalar && start->isScalar();
// Get data type; integer continuous interval is always double
dtype_p = itsStart->dataType();
if (dtype_p == NTInt) {
dtype_p = NTDouble;
}
}
if (end) {
itsEnd = end->getRep();
isScalar = isScalar && end->isScalar();
NodeDataType etype = itsEnd->dataType();
if (etype == NTInt) {
etype = NTDouble;
}
if (start && etype != dtype_p) {
throw (TableInvExpr ("start=:=end must have equal data types"));
}
dtype_p = etype;
}
if (!isScalar) {
throw TableInvExpr("Scalar values must be used in start:=:end");
}
NodeDataType dt = dataType();
if (dt != NTInt && dt != NTDouble && dt != NTString
&& dt != NTDate) {
throw (TableInvExpr ("start:=:end only valid for Int, Double,"
" String or Date"));
}
// Find unit and adapt units if needed.
setUnit (TableExprNodeUnit::adaptUnits (itsStart, itsEnd, itsIncr));
checkTable();
}
void TableExprNodeSetElem::adaptSetUnits (const Unit& unit)
{
if (! unit.empty()) {
if (itsStart) TableExprNodeUnit::adaptUnit (itsStart, unit);
if (itsEnd) TableExprNodeUnit::adaptUnit (itsEnd, unit);
if (itsIncr) TableExprNodeUnit::adaptUnit (itsIncr, unit);
setUnit (unit);
}
}
void TableExprNodeSetElem::show (ostream& os, uInt indent) const
{
TableExprNodeRep::show (os, indent);
if (itsStart) {
os << "start: ";
itsStart->show (os, indent+2);
}
if (itsEnd) {
os << "end: ";
itsEnd->show (os, indent+2);
}
if (itsIncr) {
os << "incr: ";
itsIncr->show (os, indent+2);
}
}
void TableExprNodeSetElem::getAggrNodes (vector<TableExprNodeRep*>& aggr)
{
if (itsStart) {
itsStart->getAggrNodes (aggr);
}
if (itsEnd) {
itsEnd->getAggrNodes (aggr);
}
if (itsIncr) {
itsIncr->getAggrNodes (aggr);
}
}
void TableExprNodeSetElem::getColumnNodes (vector<TableExprNodeRep*>& cols)
{
if (itsStart) {
itsStart->getColumnNodes (cols);
}
if (itsEnd) {
itsEnd->getColumnNodes (cols);
}
if (itsIncr) {
itsIncr->getColumnNodes (cols);
}
}
void TableExprNodeSetElem::checkTable()
{
table_p = Table();
checkTablePtr (itsStart);
checkTablePtr (itsEnd);
checkTablePtr (itsIncr);
exprtype_p = Constant;
fillExprType (itsStart);
fillExprType (itsEnd);
fillExprType (itsIncr);
}
TableExprNodeSetElem* TableExprNodeSetElem::evaluate
(const TableExprId& id) const
{
TENShPtr start;
TENShPtr end;
TENShPtr incr;
switch (dataType()) {
case NTBool:
if (itsStart) {
start = new TableExprNodeConstBool (itsStart->getBool (id));
}
break;
case NTInt:
if (itsStart) {
start = new TableExprNodeConstInt (itsStart->getInt (id));
}
if (itsEnd) {
end = new TableExprNodeConstInt (itsEnd->getInt (id));
}
if (itsIncr) {
incr = new TableExprNodeConstInt (itsIncr->getInt (id));
}
break;
case NTDouble:
if (itsStart) {
start = new TableExprNodeConstDouble (itsStart->getDouble (id));
}
if (itsEnd) {
end = new TableExprNodeConstDouble (itsEnd->getDouble (id));
}
if (itsIncr) {
incr = new TableExprNodeConstDouble (itsIncr->getDouble (id));
}
break;
case NTComplex:
if (itsStart) {
start = new TableExprNodeConstDComplex
(itsStart->getDComplex (id));
}
break;
case NTString:
if (itsStart) {
start = new TableExprNodeConstString (itsStart->getString (id));
}
if (itsEnd) {
end = new TableExprNodeConstString (itsEnd->getString (id));
}
break;
case NTDate:
if (itsStart) {
start = new TableExprNodeConstDate (itsStart->getDate (id));
}
if (itsEnd) {
end = new TableExprNodeConstDate (itsEnd->getDate (id));
}
if (itsIncr) {
incr = new TableExprNodeConstDouble (itsIncr->getDouble (id));
}
break;
default:
TableExprNode::throwInvDT ("TableExprNodeSetElem::evaluate");
}
return new TableExprNodeSetElem (*this, start, end, incr);
}
void TableExprNodeSetElem::fillVector (Vector<Bool>& vec, Int64& cnt,
const TableExprId& id) const
{
DebugAssert (itsSingle, AipsError);
Int64 n = vec.size();
if (n < cnt+1) {
vec.resize (cnt+64, True);
}
vec(cnt++) = itsStart->getBool (id);
}
void TableExprNodeSetElem::fillVector (Vector<Int64>& vec, Int64& cnt,
const TableExprId& id) const
{
DebugAssert (itsDiscrete, AipsError);
Int64 start = itsStart==0 ? 0 : itsStart->getInt (id);
Int64 end = itsEnd==0 ? start : itsEnd->getInt (id);
Int64 incr = itsIncr==0 ? 1 : itsIncr->getInt (id);
if (incr == 0) {
throw TableInvExpr("Increment in a range must be non-zero");
}
Int64 nval = std::max(Int64(0), 1 + (end - start) / incr);
if (itsEndExcl && nval > 0) {
Int64 rngend = start + (nval-1)*incr;
if (rngend == end) {
nval -= 1;
}
}
Int64 n = vec.size();
if (n < cnt+nval) {
vec.resize (cnt+max(64,nval), True);
}
for (Int64 i=0; i<nval; i++) {
vec(cnt++) = start;
start += incr;
}
}
void TableExprNodeSetElem::fillVector (Vector<Double>& vec, Int64& cnt,
const TableExprId& id) const
{
DebugAssert (itsDiscrete, AipsError);
Double start = itsStart==0 ? 0 : itsStart->getDouble (id);
Double end = itsEnd==0 ? start : itsEnd->getDouble (id);
Double incr = itsIncr==0 ? 1 : itsIncr->getDouble (id);
if (incr == 0) {
throw TableInvExpr("Increment in a range must be non-zero");
}
Int64 nval = std::max(Int64(0), Int64(1 + (end - start) / incr + 1e-10));
if (itsEndExcl && nval > 0) {
Double rngend = start + (nval-1)*incr;
if (near(rngend, end) || (end == 0 && nearAbs(rngend, end))) {
nval -= 1;
}
}
Int64 n = vec.size();
if (n < cnt+nval) {
vec.resize (cnt+max(64,nval), True);
}
for (Int64 i=0; i<nval; i++) {
vec(cnt++) = start;
start += incr;
}
}
void TableExprNodeSetElem::fillVector (Vector<DComplex>& vec, Int64& cnt,
const TableExprId& id) const
{
DebugAssert (itsSingle, AipsError);
Int64 n = vec.size();
if (n < cnt+1) {
vec.resize (cnt+64, True);
}
vec(cnt++) = itsStart->getDComplex (id);
}
void TableExprNodeSetElem::fillVector (Vector<String>& vec, Int64& cnt,
const TableExprId& id) const
{
DebugAssert (itsSingle, AipsError);
Int64 n = vec.size();
if (n < cnt+1) {
vec.resize (cnt+64, True);
}
vec(cnt++) = itsStart->getString (id);
}
void TableExprNodeSetElem::fillVector (Vector<MVTime>& vec, Int64& cnt,
const TableExprId& id) const
{
DebugAssert (itsDiscrete, AipsError);
Double start = itsStart==0 ? 0 : Double(itsStart->getDate (id));
Double end = itsEnd==0 ? start : Double(itsEnd->getDate (id));
Double incr = itsIncr==0 ? 1 : itsIncr->getDouble (id);
if (incr == 0) {
throw TableInvExpr("Increment in a range must be non-zero");
}
Int64 nval = std::max(Int64(0), Int64(1 + (end - start) / incr + 1e-10));
if (itsEndExcl && nval > 0) {
Double rngend = start + (nval-1)*incr;
if (near(rngend, end) || (end == 0 && nearAbs(rngend, end))) {
nval -= 1;
}
}
Int64 n = vec.size();
if (n < cnt+nval) {
vec.resize (cnt+max(64,nval), True);
}
for (Int64 i=0; i<nval; i++) {
vec(cnt++) = start;
start += incr;
}
}
void TableExprNodeSetElem::matchBool (Bool* match, const Bool* value,
size_t nval,
const TableExprId& id) const
{
DebugAssert (itsSingle, AipsError);
Bool start = itsStart->getBool (id);
Bool* lastVal = match + nval;
while (match < lastVal) {
if (*value == start) {
*match = True;
}
value++;
match++;
}
}
void TableExprNodeSetElem::matchInt (Bool* match, const Int64* value,
size_t nval,
const TableExprId& id) const
{
Int64 start = itsStart==0 ? 0 : itsStart->getInt (id);
Int64 end = itsEnd==0 ? start : itsEnd->getInt (id);
Int64 incr = itsIncr==0 ? 1 : itsIncr->getInt (id);
if (incr == 0) {
throw TableInvExpr("Increment in a range must be non-zero");
}
Bool* lastVal = match + nval;
if (itsSingle) {
while (match < lastVal) {
if (*value == start) {
*match = True;
}
value++;
match++;
}
} else if (itsDiscrete) {
end -= start;
if (itsEndExcl) {
end -= 1;
}
while (match < lastVal) {
Int64 tmp = *value - start;
if (incr > 0) {
if (tmp >= 0 && (itsEnd == 0 || tmp <= end)) {
if (tmp%incr == 0) {
*match = True;
}
}
} else {
if (tmp <= 0 && (itsEnd == 0 || tmp >= end)) {
if (tmp%incr == 0) {
*match = True;
}
}
}
value++;
match++;
}
}else{
while (match < lastVal) {
Int64 tmp = *value;
if ((itsStart == 0
|| tmp > start || (itsLeftClosed && tmp == start))
&& (itsEnd == 0
|| tmp < end || (itsRightClosed && tmp == end))) {
*match = True;
}
value++;
match++;
}
}
}
void TableExprNodeSetElem::matchDouble (Bool* match, const Double* value,
size_t nval,
const TableExprId& id) const
{
Double start = itsStart==0 ? 0 : itsStart->getDouble (id);
Double end = itsEnd==0 ? start : itsEnd->getDouble (id);
Double incr = itsIncr==0 ? 1 : itsIncr->getDouble (id);
if (incr == 0) {
throw TableInvExpr("Increment in a range must be non-zero");
}
Bool* lastVal = match + nval;
if (itsSingle) {
while (match < lastVal) {
if (*value == start) {
*match = True;
}
value++;
match++;
}
} else if (itsDiscrete) {
end -= start;
while (match < lastVal) {
Double tmp = *value - start;
if (incr > 0) {
if (tmp >= 0 && (itsEnd == 0 || tmp < end ||
(!itsEndExcl && tmp==end))) {
if (near(tmp, incr*Int64(tmp/incr + 0.5))) {
*match = True;
}
}
} else {
if (tmp <= 0 && (itsEnd == 0 || tmp > end ||
(!itsEndExcl && tmp==end))) {
if (near(tmp, incr*Int64(tmp/incr + 0.5))) {
*match = True;
}
}
}
value++;
match++;
}
}else{
while (match < lastVal) {
Double tmp = *value;
if ((itsStart == 0
|| tmp > start || (itsLeftClosed && tmp == start))
&& (itsEnd == 0
|| tmp < end || (itsRightClosed && tmp == end))) {
*match = True;
}
value++;
match++;
}
}
}
void TableExprNodeSetElem::matchDComplex (Bool* match, const DComplex* value,
size_t nval,
const TableExprId& id) const
{
DebugAssert (itsSingle, AipsError);
DComplex start = itsStart->getDComplex (id);
Bool* lastVal = match + nval;
while (match < lastVal) {
if (*value == start) {
*match = True;
}
value++;
match++;
}
}
void TableExprNodeSetElem::matchString (Bool* match, const String* value,
size_t nval,
const TableExprId& id) const
{
String start;
if (itsStart) {
start = itsStart->getString (id);
}
String end;
if (itsEnd) {
end = itsEnd->getString (id);
}
Bool* lastVal = match + nval;
if (itsDiscrete) {
DebugAssert (itsSingle, AipsError);
while (match < lastVal) {
if (*value == start) {
*match = True;
}
value++;
match++;
}
}else{
while (match < lastVal) {
if ((itsStart == 0
|| *value > start || (itsLeftClosed && *value == start))
&& (itsEnd == 0
|| *value < end || (itsRightClosed && *value == end))) {
*match = True;
}
value++;
match++;
}
}
}
void TableExprNodeSetElem::matchDate (Bool* match, const MVTime* value,
size_t nval,
const TableExprId& id) const
{
Double start = itsStart==0 ? 0 : Double(itsStart->getDate (id));
Double end = itsEnd==0 ? start : Double(itsEnd->getDate (id));
Double incr = itsIncr==0 ? 1 : itsIncr->getDouble (id);
if (incr == 0) {
throw TableInvExpr("Increment in a range must be non-zero");
}
Bool* lastVal = match + nval;
if (itsSingle) {
while (match < lastVal) {
if (Double(*value) == start) {
*match = True;
}
value++;
match++;
}
} else if (itsDiscrete) {
end -= start;
while (match < lastVal) {
Double tmp = Double(*value) - start;
if (incr > 0) {
if (tmp >= 0 && (itsEnd == 0 || tmp < end ||
(!itsEndExcl && tmp==end))) {
if (near(tmp, incr*Int64(tmp/incr + 0.5))) {
*match = True;
}
}
} else {
if (tmp <= 0 && (itsEnd == 0 || tmp > end ||
(!itsEndExcl && tmp==end))) {
if (near(tmp, incr*Int64(tmp/incr + 0.5))) {
*match = True;
}
}
}
value++;
match++;
}
}else{
while (match < lastVal) {
Double tmp = *value;
if ((itsStart == 0
|| tmp > start || (itsLeftClosed && tmp == start))
&& (itsEnd == 0
|| tmp < end || (itsRightClosed && tmp == end))) {
*match = True;
}
value++;
match++;
}
}
}
TableExprNodeSet::TableExprNodeSet()
: TableExprNodeRep (NTNumeric, VTSet, OtUndef, Table()),
itsSingle (True),
itsDiscrete (True),
itsBounded (True),
itsCheckTypes (True),
itsAllIntervals (False),
itsFindFunc (0)
{}
TableExprNodeSet::TableExprNodeSet (const IPosition& indices)
: TableExprNodeRep (NTInt, VTSet, OtUndef, Table()),
itsSingle (True),
itsDiscrete (True),
itsBounded (True),
itsCheckTypes (False),
itsAllIntervals (False),
itsFindFunc (0)
{
uInt n = indices.size();
itsElems.resize (n);
for (uInt i=0; i<n; i++) {
itsElems[i] = new TableExprNodeSetElem (TableExprNode (Int64(indices(i))));
}
}
TableExprNodeSet::TableExprNodeSet (const Slicer& indices)
: TableExprNodeRep (NTInt, VTSet, OtUndef, Table()),
itsSingle (False),
itsDiscrete (True),
itsBounded (True),
itsCheckTypes (False),
itsAllIntervals (False),
itsFindFunc (0)
{
TableExprNode start;
TableExprNode end;
TableExprNode* startp;
TableExprNode* endp;
uInt n = indices.ndim();
itsElems.resize (n);
for (uInt i=0; i<n; i++) {
startp = endp = 0;
if (indices.start()(i) != Slicer::MimicSource) {
start = TableExprNode (Int64(indices.start()(i)));
startp = &start;
}
if (indices.end()(i) != Slicer::MimicSource) {
end = TableExprNode (Int64(indices.end()(i)));
endp = &end;
}
TableExprNode incr (Int64(indices.stride()(i)));
itsElems[i] = new TableExprNodeSetElem (startp, endp, &incr);
}
}
TableExprNodeSet::TableExprNodeSet (const Vector<rownr_t>& rownrs,
const TableExprNodeSet& set)
: TableExprNodeRep (set.dataType(), VTSet, OtUndef, Table()),
itsElems (rownrs.size() * set.size()),
itsSingle (set.isSingle()),
itsDiscrete (set.isDiscrete()),
itsBounded (set.isBounded()),
itsCheckTypes (False),
itsAllIntervals (False),
itsFindFunc (0)
{
// Fill in all values.
size_t nrel = set.size();
for (rownr_t i=0; i<rownrs.size(); i++) {
for (size_t j=0; j<nrel; j++) {
itsElems[j+i*nrel] = set[j].evaluate (rownrs[i]);
}
}
// Try to combine multiple intervals; it can improve performance a lot.
if (rownrs.size() > 1 && !isSingle() && !isDiscrete()) {
if (set.dataType() == NTInt) {
combineIntIntervals();
} else if (set.dataType() == NTDouble) {
combineDoubleIntervals();
} else if (set.dataType() == NTDate) {
combineDateIntervals();
}
}
setUnit (set.unit());
}
TableExprNodeSet::TableExprNodeSet (const TableExprNodeSet& that)
: TableExprNodeRep (that),
itsSingle (that.itsSingle),
itsDiscrete (that.itsDiscrete),
itsBounded (that.itsBounded),
itsCheckTypes (that.itsCheckTypes),
itsAllIntervals (that.itsAllIntervals),
itsStart (that.itsStart),
itsEnd (that.itsEnd),
itsFindFunc (that.itsFindFunc)
{
size_t n = that.itsElems.size();
itsElems.resize (n);
for (size_t i=0; i<n; i++) {
itsElems[i] = new TableExprNodeSetElem (*castSetElem(that.itsElems[i]));
}
}
TableExprNodeSet::~TableExprNodeSet()
{}
void TableExprNodeSet::combineIntIntervals()
{
DebugAssert (itsElems.size() > 0, AipsError);
// Make an id (with an arbitrary row number) for the gets.
TableExprId id(0);
std::vector<TENShPtr> elems(1);
TableExprNodeSetElem& elem = *(castItsElem(0));
if (elem.start() == 0) {
// No start value, so only the highest end value is relevant.
// Make a single interval with the used open/closed-ness.
Int64 val = elem.end()->getInt(id);
for (size_t i=1; i<itsElems.size(); i++) {
Int64 valn = castItsElem(i)->end()->getInt(id);
if (valn > val) {
val = valn;
}
}
elems[0] = new TableExprNodeSetElem(TableExprNode(val),
elem.isRightClosed());
} else if (elem.end() == 0) {
// No end value, so only the lowest start value is relevant.
Int64 val = elem.start()->getInt(id);
for (size_t i=1; i<itsElems.size(); i++) {
Int64 valn = castItsElem(i)->start()->getInt(id);
if (valn < val) {
val = valn;
}
}
elems[0] = new TableExprNodeSetElem(elem.isLeftClosed(),
TableExprNode(val));
} else {
// The intervals contain both a start and an end value.
// Make the block large enough for all possible intervals.
elems.resize (itsElems.size());
size_t nelem = 0;
// Get all start values and sort them (indirectly) in ascending order.
Block<Int64> vals(itsElems.size());
for (size_t i=0; i<itsElems.size(); i++) {
vals[i] = castItsElem(i)->start()->getInt(id);
}
Vector<uInt> index;
GenSortIndirect<Int64,uInt>::sort (index, vals, vals.size());
// Get the start and end value of first interval in sorted list.
Int64 stval = vals[index[0]];
Int64 endval = castItsElem(index[0])->end()->getInt(id);
// Loop through the next intervals and combine if possible.
for (uInt i=1; i<index.size(); i++) {
Int inx = index[i];
Int64 st2 = vals[inx];
Int64 end2 = castItsElem(inx)->end()->getInt(id);
// Combine intervals if they overlap.
// They do if the next interval starts before end of this one
// or if starting at the end and one side of the interval is closed.
if (st2 < endval ||
(st2 == endval &&
(elem.isLeftClosed() || elem.isRightClosed()))) {
// Overlap; update end if higher.
if (end2 > endval) {
endval = end2;
}
} else {
// No overlap, so create the interval found and start a new one.
elems[nelem++] = new TableExprNodeSetElem(elem.isLeftClosed(),
stval,
endval,
elem.isRightClosed());
stval = st2;
endval = end2;
}
}
// Create the last interval and resize the array to #intervals found.
elems[nelem++] = new TableExprNodeSetElem(elem.isLeftClosed(),
stval,
endval,
elem.isRightClosed());
elems.resize (nelem);
// Store the values in a start and an end array.
itsStart.resize (nelem);
itsEnd.resize (nelem);
for (size_t i=0; i<nelem; i++) {
itsStart[i] = castSetElem(elems[i])->start()->getInt(id);
itsEnd[i] = castSetElem(elems[i])->end()->getInt(id);
}
setFindFunc (elem.isLeftClosed(), elem.isRightClosed());
itsAllIntervals = True;
}
// Replace by new ones.
itsElems = elems;
}
void TableExprNodeSet::combineDoubleIntervals()
{
DebugAssert (itsElems.size() > 0, AipsError);
// Make an id (with an arbitrary row number) for the gets.
TableExprId id(0);
std::vector<TENShPtr> elems(1);
TableExprNodeSetElem& elem = *(castItsElem(0));
if (elem.start() == 0) {
// No start value, so only the highest end value is relevant.
// Make a single interval with the used open/closed-ness.
Double val = elem.end()->getDouble(id);
for (size_t i=1; i<itsElems.size(); i++) {
Double valn = castItsElem(i)->end()->getDouble(id);
if (valn > val) {
val = valn;
}
}
elems[0] = new TableExprNodeSetElem(TableExprNode(val),
elem.isRightClosed());
} else if (elem.end() == 0) {
// No end value, so only the lowest start value is relevant.
Double val = elem.start()->getDouble(id);
for (size_t i=1; i<itsElems.size(); i++) {
Double valn = castItsElem(i)->start()->getDouble(id);
if (valn < val) {
val = valn;
}
}
elems[0] = new TableExprNodeSetElem(elem.isLeftClosed(),
TableExprNode(val));
} else {
// The intervals contain both a start and an end value.
// Make the block large enough for all possible intervals.
elems.resize (itsElems.size());
size_t nelem = 0;
// Get all start values and sort them (indirectly) in ascending order.
Block<Double> vals(itsElems.size());
for (size_t i=0; i<itsElems.size(); i++) {
vals[i] = castItsElem(i)->start()->getDouble(id);
}
Vector<uInt> index;
GenSortIndirect<Double,uInt>::sort (index, vals, vals.size());
// Get the start and end value of first interval in sorted list.
Double stval = vals[index[0]];
Double endval = castItsElem(index[0])->end()->getDouble(id);
// Loop through the next intervals and combine if possible.
for (uInt i=1; i<index.size(); i++) {
Int inx = index[i];
Double st2 = vals[inx];
Double end2 = castItsElem(inx)->end()->getDouble(id);
// Combine intervals if they overlap.
// They do if the next interval starts before end of this one
// or if starting at the end and one side of the interval is closed.
if (st2 < endval ||
(st2 == endval &&
(elem.isLeftClosed() || elem.isRightClosed()))) {
// Overlap; update end if higher.
if (end2 > endval) {
endval = end2;
}
} else {
// No overlap, so create the interval found and start a new one.
elems[nelem++] = new TableExprNodeSetElem(elem.isLeftClosed(),
stval,
endval,
elem.isRightClosed());
stval = st2;
endval = end2;
}
}
// Create the last interval and resize the array to #intervals found.
elems[nelem++] = new TableExprNodeSetElem(elem.isLeftClosed(),
stval,
endval,
elem.isRightClosed());
elems.resize (nelem);
// Store the values in a start and an end array.
itsStart.resize (nelem);
itsEnd.resize (nelem);
for (size_t i=0; i<nelem; i++) {
itsStart[i] = castSetElem(elems[i])->start()->getDouble(id);
itsEnd[i] = castSetElem(elems[i])->end()->getDouble(id);
}
setFindFunc (elem.isLeftClosed(), elem.isRightClosed());
itsAllIntervals = True;
}
// Replace by new ones.
itsElems = elems;
}
void TableExprNodeSet::combineDateIntervals()
{
DebugAssert (itsElems.size() > 0, AipsError);
// Make an id (with an arbitrary row number) for the gets.
// Note that this function uses the automatic Double<->MVTime conversions.
TableExprId id(0);
std::vector<TENShPtr> elems(1);
TableExprNodeSetElem& elem = *(castItsElem(0));
if (elem.start() == 0) {
// No start value, so only the highest end value is relevant.
// Make a single interval with the used open/closed-ness.
Double val = elem.end()->getDate(id);
for (size_t i=1; i<itsElems.size(); i++) {
Double valn = castItsElem(i)->end()->getDate(id);
if (valn > val) {
val = valn;
}
}
elems[0] = new TableExprNodeSetElem
(TableExprNode(new TableExprNodeConstDate(val)),
elem.isRightClosed());
} else if (elem.end() == 0) {
// No end value, so only the lowest start value is relevant.
Double val = elem.start()->getDate(id);
for (size_t i=1; i<itsElems.size(); i++) {
Double valn = castItsElem(i)->start()->getDate(id);
if (valn < val) {
val = valn;
}
}
elems[0] = new TableExprNodeSetElem
(elem.isLeftClosed(),
TableExprNode(new TableExprNodeConstDate(val)));
} else {
// The intervals contain both a start and an end value.
// Make the block large enough for all possible intervals.
elems.resize (itsElems.size());
size_t nelem = 0;
// Get all start values and sort them (indirectly) in ascending order.
Block<Double> vals(itsElems.size());
for (size_t i=0; i<itsElems.size(); i++) {
vals[i] = castItsElem(i)->start()->getDate(id);
}
Vector<uInt> index;
GenSortIndirect<Double,uInt>::sort (index, vals, vals.size());
// Get the start and end value of first interval in sorted list.
Double stval = vals[index[0]];
Double endval = castItsElem(index[0])->end()->getDate(id);
// Loop through the next intervals and combine if possible.
for (uInt i=1; i<index.size(); i++) {
Int inx = index[i];
Double st2 = vals[inx];
Double end2 = castItsElem(inx)->end()->getDate(id);
// Combine intervals if they overlap.
// They do if the next interval starts before end of this one
// or if starting at the end and one side of the interval is closed.
if (st2 < endval ||
(st2 == endval &&
(elem.isLeftClosed() || elem.isRightClosed()))) {
// Overlap; update end if higher.
if (end2 > endval) {
endval = end2;
}
} else {
// No overlap, so create the interval found and start a new one.
elems[nelem++] = new TableExprNodeSetElem
(elem.isLeftClosed(),
new TableExprNodeConstDate(stval),
new TableExprNodeConstDate(endval),
elem.isRightClosed());
stval = st2;
endval = end2;
}
}
// Create the last interval and resize the array to #intervals found.
elems[nelem++] = new TableExprNodeSetElem
(elem.isLeftClosed(),
new TableExprNodeConstDate(stval),
new TableExprNodeConstDate(endval),
elem.isRightClosed());
elems.resize (nelem);
// Store the values in a start and an end array.
itsStart.resize (nelem);
itsEnd.resize (nelem);
for (size_t i=0; i<nelem; i++) {
itsStart[i] = castSetElem(elems[i])->start()->getDate(id);
itsEnd[i] = castSetElem(elems[i])->end()->getDate(id);
}
setFindFunc (elem.isLeftClosed(), elem.isRightClosed());
itsAllIntervals = True;
}
// Replace by new ones.
itsElems = elems;
}
void TableExprNodeSet::setFindFunc (Bool isLeftClosed, Bool isRightClosed)
{
if (isLeftClosed) {
if (isRightClosed) {
itsFindFunc = &TableExprNodeSet::findClosedClosed;
} else {
itsFindFunc = &TableExprNodeSet::findClosedOpen;
}
} else {
if (isRightClosed) {
itsFindFunc = &TableExprNodeSet::findOpenClosed;
} else {
itsFindFunc = &TableExprNodeSet::findOpenOpen;
}
}
}
void TableExprNodeSet::add (const TableExprNodeSetElem& elem,
Bool adaptType)
{
size_t n = itsElems.size();
itsElems.resize (n+1);
itsElems[n] = new TableExprNodeSetElem (elem);
// Set and adapt unit as needed.
if (unit().empty()) {
setUnit (elem.unit());
}
// See if the set properties change.
if (! elem.isSingle()) {
itsSingle = False;
if (! elem.isDiscrete()) {
itsDiscrete = False;
itsBounded = False;
} else {
if (elem.end() == 0) {
// Note that an undefined start defaults to 0, this is bounded.
itsBounded = False;
}
}
}
if (n == 0) {
dtype_p = elem.dataType();
} else if (adaptType) {
// Determine the highest data type.
// Note: using OtEQ works well for all types (including dates).
dtype_p = TableExprNodeBinary::getDT (dtype_p, elem.dataType(),
OtEQ);
}
checkTablePtr (itsElems[n]);
fillExprType (itsElems[n]);
}
void TableExprNodeSet::adaptSetUnits (const Unit& unit)
{
if (! unit.empty()) {
for (size_t i=0; i<itsElems.size(); i++) {
itsElems[i]->adaptSetUnits (unit);
}
setUnit (unit);
}
}
void TableExprNodeSet::checkEqualDataTypes() const
{
if (itsCheckTypes) {
for (size_t i=0; i<itsElems.size(); i++) {
if (itsElems[i]->dataType() != dtype_p) {
throw TableInvExpr ("Set elements must have equal data types");
}
}
}
}
void TableExprNodeSet::show (ostream& os, uInt indent) const
{
TableExprNodeRep::show (os, indent);
for (size_t j=0; j<itsElems.size(); j++) {
itsElems[j]->show (os, indent+2);
}
}
void TableExprNodeSet::getAggrNodes (vector<TableExprNodeRep*>& aggr)
{
for (size_t j=0; j<itsElems.size(); j++) {
itsElems[j]->getAggrNodes (aggr);
}
}
void TableExprNodeSet::getColumnNodes (vector<TableExprNodeRep*>& cols)
{
for (size_t j=0; j<itsElems.size(); j++) {
itsElems[j]->getColumnNodes (cols);
}
}
Bool TableExprNodeSet::hasArrays() const
{
//# Check if a value is an array?
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
const TableExprNodeSetElem& elem = *(castItsElem(i));
if (elem.start() && elem.start()->valueType() == VTArray) {
return True;
}
if (elem.end() && elem.end()->valueType() == VTArray) {
return True;
}
if (elem.increment() && elem.increment()->valueType() == VTArray) {
return True;
}
}
return False;
}
TENShPtr TableExprNodeSet::setOrArray() const
{
// A set where elements have different unit types cannot be turned
// into an array.
if (! unit().empty()) {
Quantity q(1., unit());
size_t n = size();
for (size_t i=0; i<n; i++) {
if (! itsElems[i]->unit().empty()) {
if (! q.isConform (itsElems[i]->unit())) {
return new TableExprNodeSet (*this);
}
}
}
// No different units, so adapt elements to first unit.
for (size_t i=0; i<n; i++) {
itsElems[i]->adaptSetUnits (unit());
}
}
// If discrete, all start values should be filled in.
if (itsDiscrete) {
size_t n = size();
for (size_t i=0; i<n; i++) {
if (castItsElem(i)->start() == 0) {
throw (TableInvExpr ("no start value in discrete interval"));
}
}
}
// If the set is bounded, it can be converted to an array.
if (itsBounded) {
// If it is const, that can be done immediately.
if (isConstant()) {
return toConstArray();
}
}
TableExprNodeSet* set = new TableExprNodeSet (*this);
if (itsBounded) {
// Set the type to VTArray; the getArray functions
// will convert the set to an array for each row.
set->setValueType (VTArray);
if (itsSingle && !hasArrays()) {
set->ndim_p = 1;
set->shape_p = IPosition (1, size());
}
}
return set;
}
TENShPtr TableExprNodeSet::toConstArray() const
{
// Construct the correct const array object.
TENShPtr tsnptr;
switch (dataType()) {
case NTBool:
tsnptr = new TableExprNodeArrayConstBool (toArray<Bool>(0));
break;
case NTInt:
tsnptr = new TableExprNodeArrayConstInt (toArray<Int64>(0));
break;
case NTDouble:
tsnptr = new TableExprNodeArrayConstDouble (toArray<Double>(0));
break;
case NTComplex:
tsnptr = new TableExprNodeArrayConstDComplex (toArray<DComplex>(0));
break;
case NTString:
tsnptr = new TableExprNodeArrayConstString (toArray<String>(0));
break;
case NTDate:
tsnptr = new TableExprNodeArrayConstDate (toArray<MVTime>(0));
break;
default:
TableExprNode::throwInvDT ("TableExprNodeSet::toConstArray");
}
tsnptr->setUnit (unit());
return tsnptr;
}
MArray<Bool> TableExprNodeSet::getArrayBool (const TableExprId& id)
{
return toArray<Bool> (id);
}
MArray<Int64> TableExprNodeSet::getArrayInt (const TableExprId& id)
{
return toArray<Int64> (id);
}
MArray<Double> TableExprNodeSet::getArrayDouble (const TableExprId& id)
{
return toArray<Double> (id);
}
MArray<DComplex> TableExprNodeSet::getArrayDComplex (const TableExprId& id)
{
return toArray<DComplex> (id);
}
MArray<String> TableExprNodeSet::getArrayString (const TableExprId& id)
{
return toArray<String> (id);
}
MArray<MVTime> TableExprNodeSet::getArrayDate (const TableExprId& id)
{
return toArray<MVTime> (id);
}
Bool TableExprNodeSet::findOpenOpen (Double value)
{
size_t n = itsElems.size();
if (value >= itsEnd[n-1]) {
return False;
}
for (size_t i=0; i<n; i++) {
if (value <= itsStart[i]) {
return False;
}
if (value < itsEnd[i]) {
return True;
}
}
return False;
}
Bool TableExprNodeSet::findOpenClosed (Double value)
{
size_t n = itsElems.size();
if (value > itsEnd[n-1]) {
return False;
}
for (size_t i=0; i<n; i++) {
if (value <= itsStart[i]) {
return False;
}
if (value <= itsEnd[i]) {
return True;
}
}
return False;
}
Bool TableExprNodeSet::findClosedOpen (Double value)
{
size_t n = itsElems.size();
if (value >= itsEnd[n-1]) {
return False;
}
for (size_t i=0; i<n; i++) {
if (value < itsStart[i]) {
return False;
}
if (value < itsEnd[i]) {
return True;
}
}
return False;
}
Bool TableExprNodeSet::findClosedClosed (Double value)
{
size_t n = itsElems.size();
if (value > itsEnd[n-1]) {
return False;
}
for (size_t i=0; i<n; i++) {
if (value < itsStart[i]) {
return False;
}
if (value <= itsEnd[i]) {
return True;
}
}
return False;
}
Bool TableExprNodeSet::hasBool (const TableExprId& id, Bool value)
{
Bool result = False;
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchBool (&result, &value, 1, id);
}
return result;
}
Bool TableExprNodeSet::hasInt (const TableExprId& id, Int64 value)
{
if (itsAllIntervals) {
return (this->*itsFindFunc) (value);
}
Bool result = False;
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchInt (&result, &value, 1, id);
}
return result;
}
Bool TableExprNodeSet::hasDouble (const TableExprId& id, Double value)
{
if (itsAllIntervals) {
return (this->*itsFindFunc) (value);
}
Bool result = False;
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchDouble (&result, &value, 1, id);
}
return result;
}
Bool TableExprNodeSet::hasDComplex (const TableExprId& id,
const DComplex& value)
{
Bool result = False;
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchDComplex (&result, &value, 1, id);
}
return result;
}
Bool TableExprNodeSet::hasString (const TableExprId& id, const String& value)
{
Bool result = False;
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchString (&result, &value, 1, id);
}
return result;
}
Bool TableExprNodeSet::hasDate (const TableExprId& id, const MVTime& value)
{
if (itsAllIntervals) {
return (this->*itsFindFunc) (value);
}
Bool result = False;
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchDate (&result, &value, 1, id);
}
return result;
}
MArray<Bool> TableExprNodeSet::hasArrayBool (const TableExprId& id,
const MArray<Bool>& value)
{
Array<Bool> result(value.shape());
result.set (False);
Bool deleteIn, deleteOut;
const Bool* in = value.array().getStorage (deleteIn);
Bool* out = result.getStorage (deleteOut);
size_t nval = value.size();
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchBool (out, in, nval, id);
}
value.array().freeStorage (in, deleteIn);
result.putStorage (out, deleteOut);
return MArray<Bool> (result, value.mask());
}
MArray<Bool> TableExprNodeSet::hasArrayInt (const TableExprId& id,
const MArray<Int64>& value)
{
Array<Bool> result(value.shape());
result.set (False);
Bool deleteIn, deleteOut;
const Int64* in = value.array().getStorage (deleteIn);
Bool* out = result.getStorage (deleteOut);
size_t nval = value.size();
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchInt (out, in, nval, id);
}
value.array().freeStorage (in, deleteIn);
result.putStorage (out, deleteOut);
return MArray<Bool> (result, value.mask());
}
MArray<Bool> TableExprNodeSet::hasArrayDouble (const TableExprId& id,
const MArray<Double>& value)
{
Array<Bool> result(value.shape());
result.set (False);
Bool deleteIn, deleteOut;
const Double* in = value.array().getStorage (deleteIn);
Bool* out = result.getStorage (deleteOut);
size_t nval = value.size();
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchDouble (out, in, nval, id);
}
value.array().freeStorage (in, deleteIn);
result.putStorage (out, deleteOut);
return MArray<Bool> (result, value.mask());
}
MArray<Bool> TableExprNodeSet::hasArrayDComplex (const TableExprId& id,
const MArray<DComplex>& value)
{
Array<Bool> result(value.shape());
result.set (False);
Bool deleteIn, deleteOut;
const DComplex* in = value.array().getStorage (deleteIn);
Bool* out = result.getStorage (deleteOut);
size_t nval = value.size();
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchDComplex (out, in, nval, id);
}
value.array().freeStorage (in, deleteIn);
result.putStorage (out, deleteOut);
return MArray<Bool> (result, value.mask());
}
MArray<Bool> TableExprNodeSet::hasArrayString (const TableExprId& id,
const MArray<String>& value)
{
Array<Bool> result(value.shape());
result.set (False);
Bool deleteIn, deleteOut;
const String* in = value.array().getStorage (deleteIn);
Bool* out = result.getStorage (deleteOut);
size_t nval = value.size();
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchString (out, in, nval, id);
}
value.array().freeStorage (in, deleteIn);
result.putStorage (out, deleteOut);
return MArray<Bool> (result, value.mask());
}
MArray<Bool> TableExprNodeSet::hasArrayDate (const TableExprId& id,
const MArray<MVTime>& value)
{
Array<Bool> result(value.shape());
result.set (False);
Bool deleteIn, deleteOut;
const MVTime* in = value.array().getStorage (deleteIn);
Bool* out = result.getStorage (deleteOut);
size_t nval = value.size();
size_t n = itsElems.size();
for (size_t i=0; i<n; i++) {
castItsElem(i)->matchDate (out, in, nval, id);
}
value.array().freeStorage (in, deleteIn);
result.putStorage (out, deleteOut);
return MArray<Bool> (result, value.mask());
}
} //# NAMESPACE CASACORE - END
|