示例#1
0
bool
ObjectCache::findCount(Id count_id, Count& count)
{
    Count* object = findCount(count_id);
    if (object == NULL) return false;
    count = *object;
    return true;
}
 int smallestDistancePair(vector<int>& nums, int k) {
     sort(nums.begin(), nums.end());
     int low = 0;
     int high = nums.back() - nums[0];
     while (low != high) {
         int mid = (low + high) / 2;
         int count = findCount(mid, nums); // <= mid
         if (count >= k) {
             high = mid;
         } else {
             low = mid + 1;
         }
     }
     return low;
 }
 string minWindow(string s, string t) {
     int len1 = s.length(), len2 = t.length(), start = 0, end = 0, count = 0, minLen = INT_MAX, minIndex;
     vector<int> needCount(256, 0), findCount(256, 0);
     if (len2 == 0 || len1 < len2) {
         return "";
     }
     for (int i = 0; i < len2; i ++) {
         needCount[int(t[i])] ++;
     }
     for (; end < len1; end ++) {
         int index = (int)s[end];
         if (!needCount[index]) {
             continue;
         }
         findCount[index] ++;
         if (findCount[index] <= needCount[index]) {
             count ++;
         }
         if (count == len2) {
             while (start < end) {
                 int index = (int)s[start];
                 if (!needCount[index]) {
                     start ++;
                     continue;
                 }
                 if (findCount[index] > needCount[index]) {
                     findCount[index] --;
                     start ++;
                     continue;
                 } else {
                     break;
                 }
             }
             if (minLen > end - start + 1) {
                 minLen = end - start + 1;
                 minIndex = start;
             }
         }
     }
     if (minLen == INT_MAX) {
         return "";
     }
     return s.substr(minIndex, minLen);
 }
示例#4
0
DataObject*
ObjectCache::find(Id object_id, bool cacheOnly)
{
    if (object_id == INVALID_ID)
	return NULL;

    if (_objects.find(object_id) != _objects.end())
	return _objects[object_id];

    if (cacheOnly)
	return NULL;

    DataObject object;
    if (!_db->lookup(object_id, object))
	return NULL;

    switch (object.dataType()) {
    case DataObject::ACCOUNT:		return findAccount(object_id);
    case DataObject::ADJUST_REASON:	return findAdjustReason(object_id);
    case DataObject::CARD_ADJUST:	return findCardAdjust(object_id);
    case DataObject::CHARGE:		return findCharge(object_id);
    case DataObject::CHEQUE:		return findCheque(object_id);
    case DataObject::CLAIM:		return findReceive(object_id);
    case DataObject::COMPANY:		return findCompany(object_id);
    case DataObject::COUNT:		return findCount(object_id);
    case DataObject::CUSTOMER:		return findCustomer(object_id);
    case DataObject::CUST_TYPE:		return findCustomerType(object_id);
    case DataObject::DEPT:		return findDept(object_id);
    case DataObject::DISCOUNT:		return findDiscount(object_id);
    case DataObject::EMPLOYEE:		return findEmployee(object_id);
    case DataObject::EXPENSE:		return findExpense(object_id);
    case DataObject::EXTRA:		return findExtra(object_id);
    case DataObject::GENERAL:		return findGeneral(object_id);
    case DataObject::GROUP:		return findGroup(object_id);
    case DataObject::INVOICE:		return findInvoice(object_id);
    case DataObject::ITEM:		return findItem(object_id);
    case DataObject::ITEM_ADJUST:	return findItemAdjust(object_id);
    case DataObject::ITEM_PRICE:	return findItemPrice(object_id);
    case DataObject::LABEL_BATCH:	return findLabelBatch(object_id);
    case DataObject::LOCATION:		return findLocation(object_id);
    case DataObject::NOSALE:		return findNosale(object_id);
    case DataObject::ORDER:		return findOrder(object_id);
    case DataObject::PO_TEMPLATE:	return findOrderTemplate(object_id);
    case DataObject::PAT_GROUP:		return findPatGroup(object_id);
    case DataObject::PAT_WS:		return findPatWorksheet(object_id);
    case DataObject::PAYOUT:		return findPayout(object_id);
    case DataObject::PERSONAL:		return findPersonal(object_id);
    case DataObject::PLU:		assert("Invalid data type: PLU");
    case DataObject::PRICE_BATCH:	return findPriceBatch(object_id);
    case DataObject::PROMO_BATCH:	return findPromoBatch(object_id);
    case DataObject::QUOTE:		return findQuote(object_id);
    case DataObject::RECEIPT:		return findReceipt(object_id);
    case DataObject::RECEIVE:		return findReceive(object_id);
    case DataObject::RECONCILE:		return findReconcile(object_id);
    case DataObject::RECURRING:		return findRecurring(object_id);
    case DataObject::REPORT:		assert("Invalid data type: REPORT");
    case DataObject::RETURN:		return findInvoice(object_id);
    case DataObject::SECURITY_TYPE:	return findSecurityType(object_id);
    case DataObject::SHIFT:		return findShift(object_id);
    case DataObject::SLIP:		return findSlip(object_id);
    case DataObject::STATION:		return findStation(object_id);
    case DataObject::STORE:		return findStore(object_id);
    case DataObject::SUBDEPT:		return findSubdept(object_id);
    case DataObject::TAX:		return findTax(object_id);
    case DataObject::TENDER:		return findTender(object_id);
    case DataObject::TEND_COUNT:	return findTenderCount(object_id);
    case DataObject::TEND_ADJUST:	return findTenderAdjust(object_id);
    case DataObject::TERM:		return findTerm(object_id);
    case DataObject::TODO:		return findTodo(object_id);
    case DataObject::USER:		return findUser(object_id);
    case DataObject::VENDOR:		return findVendor(object_id);
    case DataObject::WITHDRAW:		return findWithdraw(object_id);
    }

    qWarning("Unknown object type: " + object.dataTypeName());
    return NULL;
}