Example #1
0
void GroupByScan::executeGroupBy() {
  auto resultTab = createResultTableLayout();
  auto groupResults = getInputHashTable();
  // Allocate some memory for the result tab and resize the table
  resultTab->resize(groupResults->numKeys());

  pos_t row = 0;
  typename HashTableType::map_const_iterator_t it1, it2, end;
  // set iterators: in the sequential case, getInputTable() returns an AggregateHashTable, in the parallel case a HashTableView<>
  // Alternatively, a common type could be introduced
  if (_count < 1) {
    auto aggregateHashTable = std::dynamic_pointer_cast<const HashTableType>(groupResults);
    it1 = aggregateHashTable->getMapBegin();
    end = aggregateHashTable->getMapEnd();
  } else {
    auto hashTableView = std::dynamic_pointer_cast<const HashTableView<MapType, KeyType> >(groupResults);
    it1 = hashTableView->getMapBegin();
    end = hashTableView->getMapEnd();
  }
  for (it2 = it1; it1 != end; it1 = it2) {
    // outer loop over unique keys
    auto pos_list = std::make_shared<pos_list_t>();
    for (; (it2 != end) && (it1->first == it2->first); ++it2) {
      // inner loop, all keys equal to it1->first
      pos_list->push_back(it2->second);
    }
    writeGroupResult(resultTab, pos_list, row);
    row++;
  }
  this->addResult(resultTab);
}
TYPED_TEST(HashTableViewTest, no_range) {
  field_list_t columns {0, 1, 2};

  auto hashTab = std::make_shared<TypeParam>(this->table, columns);
  auto view = hashTab->view(0, 0);

  EXPECT_TRUE(view->size() == 0);
  EXPECT_TRUE(view->getMapBegin() == view->getMapEnd());
  EXPECT_TRUE(view->getMapEnd() == hashTab->getMapBegin());

  auto itMap = hashTab->getMapBegin();

  for (; itMap != hashTab->getMapEnd(); ++itMap) {
    auto key = itMap->first;
    EXPECT_TRUE(view->get(key).empty());
  }
}
TYPED_TEST(HashTableViewTest, partial_range) {
  field_list_t columns {0, 1, 2};
  auto table = this->table;
  const size_t start_row = 1, end_row = table->size() - 1;

  auto hashTab = std::make_shared<TypeParam>(table, columns);
  auto view = hashTab->view(start_row, end_row);

  EXPECT_EQ(view->size(), end_row - start_row);
  auto hashPosition = hashTab->getMapBegin();
  auto hashEnd = hashTab->getMapBegin();

  std::advance(hashPosition, start_row); // advance hashPosition to row 1
  std::advance(hashEnd, end_row);

  for (;
       hashPosition != hashEnd;
       std::advance(hashPosition, 1)) {
    auto key = hashPosition->first;
    EXPECT_TRUE(!view->get(key).empty());
  }
}
Example #4
0
void Globals::dump(TiXmlElement *root)
{
    root->SetAttribute("ActualRandomSeed",getRandom().getSeed());
    root->SetAttribute("NodeCounter",nodeCounter);
    root->SetAttribute("LinkCounter",linkCounter);
    root->SetAttribute("SpeciesCounter",speciesCounter);
    StackMap<string,double,4096>::iterator mapIterator = getMapBegin();
    StackMap<string,double,4096>::iterator mapEnd = getMapEnd();
    for (; mapIterator!=mapEnd; mapIterator++)
    {
        root->SetDoubleAttribute(
            mapIterator->first.c_str(),
            mapIterator->second
        );
    }
}