示例#1
0
文件: main.cpp 项目: CCJY/coliru
int main()
{
    std::vector<int> v;
    std::unordered_set<int> s;
    
    sorty(v.begin(), v.end());        
    sorty(s.begin(), s.end());
}
示例#2
0
文件: main.cpp 项目: CCJY/coliru
int main()
{
    std::vector<int> toOrder(10);
    std::iota(toOrder.begin(), toOrder.end(), 0);

    std::vector<double> orderBy{0.2, 9.8,  4.0,  0.01,  15.1,
                                3.3, 9.01, 9.11, 100.1, 2.03};

    std::unordered_set<double> orderBy_s(orderBy.begin(), orderBy.end());
    
    sorty(toOrder.begin(), toOrder.end(), orderBy.begin());
        
    sorty(toOrder.begin(), toOrder.end(), orderBy_s.begin());
}
void runComplexSort(uint64_t entriesCount, uint64_t pagesize, uint64_t maxMemory)
{
    EXPECT_TRUE(dbi::util::createTestFile("bin/datain", entriesCount, [&](uint32_t) {return rand();}));
    //return;
    std::vector<harriet::VariableType> columns;
    columns.push_back(harriet::VariableType::createIntegerType());
    dbi::IndexKeySchema schema{columns};
    ASSERT_EQ(schema.bytes(), 4);
    dbi::IndexKeyComparator c{schema};
    dbi::MergeSort sorty(pagesize, maxMemory, schema, c);
    EXPECT_EQ(sorty.externalsort("bin/datain", "bin/dataout"), 0);
    EXPECT_TRUE(sorty.checksort("bin/dataout"));
    remove("bin/datain");
    remove("bin/dataout");
}
TEST(MergeSortTest, Simple2)
{
   // Set up infrastructure
   std::vector<harriet::VariableType> columns;
   columns.push_back(harriet::VariableType::createIntegerType());
   columns.push_back(harriet::VariableType::createCharacterType(10));
   dbi::IndexKeySchema schema{columns};
   dbi::IndexKeyComparator c{schema};
   dbi::ExternalSort sorty(schema, c);

   // Add values
   std::vector<harriet::Value> tuple1;
   tuple1.emplace_back(harriet::Value::createInteger(1));
   tuple1.emplace_back(harriet::Value::createCharacter(string("aaa"), 10));
   auto key1 = dbi::IndexKey(std::vector<harriet::Value*>{&tuple1[0], &tuple1[1]});
   sorty.addTuple(key1);
   std::vector<harriet::Value> tuple2;
   tuple2.emplace_back(harriet::Value::createInteger(2));
   tuple2.emplace_back(harriet::Value::createCharacter(string("ccc"), 10));
   auto key2 = dbi::IndexKey(std::vector<harriet::Value*>{&tuple2[0], &tuple2[1]});
   sorty.addTuple(key2);
   std::vector<harriet::Value> tuple3;
   tuple3.emplace_back(harriet::Value::createInteger(3));
   tuple3.emplace_back(harriet::Value::createCharacter(string("sss"), 10));
   auto key3 = dbi::IndexKey(std::vector<harriet::Value*>{&tuple3[0], &tuple3[1]});
   sorty.addTuple(key3);
   std::vector<harriet::Value> tuple4;
   tuple4.emplace_back(harriet::Value::createInteger(5));
   tuple4.emplace_back(harriet::Value::createCharacter(string("bbb"), 10));
   auto key4 = dbi::IndexKey(std::vector<harriet::Value*>{&tuple4[0], &tuple4[1]});
   sorty.addTuple(key4);

   // Do sort
   sorty.sort();

   // Check result
   ASSERT_TRUE(c.equal(sorty.readNextTuple(), key1));
   ASSERT_TRUE(c.equal(sorty.readNextTuple(), key2));
   ASSERT_TRUE(c.equal(sorty.readNextTuple(), key3));
   ASSERT_TRUE(c.equal(sorty.readNextTuple(), key4));
}