示例#1
0
    int _keyIndex(int A[], int n)
    {
        // A中不存在大小相等的元素

        int low = 0;
        int high = n - 1;
        while(low <= high)
        {
            int mid = (low + high) / 2;
            int lm = _comp(A[low], A[mid]);
            int mh = _comp(A[mid], A[high]);
            int lh = _comp(A[low], A[high]);

            if(0 == lm || lm == mh)    // 最低位和中间位的元素相等或全部是有序的
                break;
            else if(lm == lh)
                high = mid;
            else if(mh == lh)
                low = mid;
            else
                assert(false);
        }

        return low;
    }
示例#2
0
	int count(const KeyT& key) const
	{
		for (auto&& k : *this) {
			if (_comp(k, key)) {
				return 1;
			}
		}
		return 0;
	}
示例#3
0
	bool insert(const KeyT& key)
	{
		for (auto&& k : *this) {
			if (_comp(k, key)) {
				return false; // like std::set we do not insert if we already have it
			}
		}
		_list.push_back(key);
		return true;
	}
示例#4
0
void test_table(void) {
  catdb::DBase::Database database("Billy_database");
  catdb::DBase::Database database1("Johnny_database");
  catdb::Column* temp = database.find_column("Cool");

  std::cout << temp->display_list() << std::endl;
  delete temp;
  temp = NULL;
  catdb::Container* container(new catdb::Container("Alex"));
  catdb::Container container1("Billy");
  catdb::Container container2("Fred");
  catdb::Container container3("Zen");

  container->insert_new_element("12.2", "Cool");
  container1.insert_new_element("14.3", "Cool");
  container2.insert_new_element("99.9", "Cool");
  container3.insert_new_element("80.2", "Cool");
  std::cout << container->obtain_element("12.2")->get_attribute() << std::endl;
  // not implemented yet!!
  database.add_container(container);
  database.add_container(&container1);
  database.add_container(&container2);
  database.add_container(&container3);

  std::cout << database.get_container("Alex")->get_container_name() << std::endl;
  std::cout << "Here is a list of stuff in this column" << std::endl;
  catdb::Column* column = database.find_column("Cool");
  catdb::Element* element = column->inspect_element("12.2", "Cool");
  column->sort_column(tools::sorting::quick_sort, tools::sorting::SORT_LITTLE_ENDIAN);
  std::cout << column->display_list() << std::endl;
  database.remove_container("Alex");
  database.remove_container("Billy");
  database.remove_container("Fred");
  database.remove_container("Zen");
  delete column;
  column = NULL;

  database1 = database;
  catdb::GreaterComparator<catdb::Element> _g;
  catdb::Comparator<catdb::Element>& _comp = catdb::LesserComparator<catdb::Element>();
  catdb::Element el1("Cooler", "Bool", "Mang");
  catdb::Element el2("Alex", "Benson", "Kol");
  std::cout << _comp(el1, el2) << std::endl;
  tools::data_structures::hash_map<int, int> mapping;


  //	if (database.get_container("Alex") == NULL)
  //	   std::cout << "Alex is deleted!" << std::endl;

  //	database.folder_create();
  //	catdb::DBase::display_db_error_msg();
}
示例#5
0
auto my_find_if_impl(T _stack, Comp&& _comp, stack_category)
{
    using traits = stack_traits<T>;
    using value_type = typename traits::value_type;
    if(traits::size(_stack) < 1){throw std::logic_error("You cannot apply find_if algorithm to empty container.");}
    value_type buffer{traits::top(_stack)};
    while(traits::size(_stack) > 1)
    {
        traits::pop(_stack);
        if(!_comp(buffer, traits::top(_stack)))
        {
            buffer = traits::top(_stack);
        }
    }
    return buffer;
}