Example #1
0
/*=============================================================================
*NAME		:TYSIniFile::Delete
			:
*MODULE		:YSIniFiles.cpp
			:
*FUNCTION	:削除処理関数です
			:
*PROCESS	:・削除処理です。
			:
*INPUT		:const int index	:インデックス番号
			:
*PROGRAMMED	:Y.Sasai
*HISTORY	:
*ID -- DATE ------- NOTE ------------------------------------------------------
*00 03.02.10 Y.Sasai Ver.0.90 初期作成
*/
void TYSIniFile::Delete( const int index )
{
	TYSIniSection* ysection = (TYSIniSection*)GetAt( FindIndex( index ) );						// 2003.02.10 Y.Sasai Ver.0.90 iniセクションクラス取得

	delete( ysection );																			// 2003.02.10 Y.Sasai Ver.0.90 破棄だ
	RemoveAt( FindIndex( index ) );																// 2003.02.10 Y.Sasai Ver.0.90 削除だ
}
Example #2
0
/*****************************************************************************
 * FindIndex: find the index of an object in an array of objects
 *****************************************************************************
 * This function assumes that p_this can be found in pp_objects. It will not
 * crash if p_this cannot be found, but will return a wrong value. It is your
 * duty to check the return value if you are not certain that the object could
 * be found for sure.
 *****************************************************************************/
static int FindIndex( vlc_object_t *p_this,
                      vlc_object_t **pp_objects, int i_count )
{
    int i_middle = i_count / 2;

    if( i_count == 0 )
    {
        return 0;
    }

    if( pp_objects[i_middle] == p_this )
    {
        return i_middle;
    }

    if( i_count == 1 )
    {
        return 0;
    }

    /* We take advantage of the sorted array */
    if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
    {
        return i_middle + FindIndex( p_this, pp_objects + i_middle,
                                             i_count - i_middle );
    }
    else
    {
        return FindIndex( p_this, pp_objects, i_middle );
    }
}
Example #3
0
size_t FindIndex(int *A, size_t n, int elem) {
    if (elem <= A[0])
        return 0;

    size_t first = 0, last = n, middle;
    while (first < last)  {
        middle = first + (last - first) / 2;

        if (elem <= A[middle])
            last = middle;
        else
            first = middle + 1;
    }

    if (middle == 0) {
        if (Abs(A[0] - elem) <= Abs(A[1] - elem))
            return 0;
        else
            return 1;
    }
    if (middle == n)
        return FindIndex(A, n, A[n-1]);
    if ( Abs(A[middle] - elem) >= Abs(A[middle-1] - elem) )
        return FindIndex(A, n, A[middle-1]);
    if (middle != n-1 && Abs(A[middle] - elem) > Abs(A[middle+1] - elem))
        return middle + 1;

    return middle;
}
Example #4
0
File: Ini.cpp Project: CrazyPro/ape
//以普通方式写一整数
bool Ini::Write(char *index, char *name, int num)
{
	//__ENTER_FUNCTION

	char string[32];
	sprintf(string, "%d", num);

	int n=FindIndex(index);
	if( n == -1 )	//新建索引
	{
		AddIndex(index);
		n=FindIndex(index);
		n=GotoLastLine(index);
		AddData(n, name, string);	//在当前位置n加一个数据
		return true;
	}

	//存在索引
	int m=FindData(n, name);
	if( m==-1 )		//新建数据
	{
		n=GotoLastLine(index);
		AddData(n, name, string);	//在当前位置n加一个数据
		return true;
	}

	//存在数据
	ModityData(n, name, string);	//修改一个数据

	return true;

	//__LEAVE_FUNCTION

//	return 0 ;
}
Example #5
0
/*================================================================ 
* 函数名:    Write
* 参数:      [in] (char *index_name)当前索引名称
*             [in] (char *key_name)KEY名称
*             [in] (char *value_name)VALUE名称
* 功能描述:   以普通方式写一字符串数据
* 返回值:    成功则返回true, 否则返false
================================================================*/
bool CIni::Write(char *index_name, char *key_name, char *value_name)
{
	int data_pos = FindIndex(index_name);
	if (data_pos == ERROR_DATA_POS)	//新建索引
	{
		AddIndex(index_name);
		data_pos = FindIndex(index_name);
		data_pos = GotoLastLine(index_name);
		AddData(data_pos, key_name, value_name);	//在当前位置n加一个数据
		return true;
	}

	//存在索引
	int data_pos2 = FindData(data_pos, key_name);
	if (data_pos2 == ERROR_DATA_POS)		//新建数据
	{
		data_pos = GotoLastLine(index_name);
		AddData(data_pos, key_name, value_name);	//在当前位置n加一个数据
		return true;
	}

	//存在数据
	ModityData(data_pos, key_name, value_name);	//修改一个数据

	return true;
}
Example #6
0
/*================================================================ 
* 函数名:    Write
* 参数:      [in] (char *index_name)当前索引名称
*             [in] (char *key_name)KEY名称
*             [in] (int int_num)整型值
* 功能描述:   以普通方式写一整数
* 返回值:    成功则返回true, 否则返false
================================================================*/
bool CIni::Write(char *index_name, char *key_name, int int_num)
{
	char string[32];
	sprintf(string, "%d", int_num);

	int data_pos = FindIndex(index_name);
	if (data_pos == ERROR_DATA_POS)	//新建索引
	{
		AddIndex(index_name);
		data_pos = FindIndex(index_name);
		data_pos = GotoLastLine(index_name);
		AddData(data_pos, key_name, string);	//在当前位置n加一个数据
		return true;
	}

	//存在索引
	int data_pos2 = FindData(data_pos, key_name);
	if (data_pos2 == ERROR_DATA_POS)		//新建数据
	{
		data_pos = GotoLastLine(index_name);
		AddData(data_pos, key_name, string);	//在当前位置n加一个数据
		return true;
	}

	//存在数据
	ModityData(data_pos, key_name, string);	//修改一个数据

	return true;
}
Example #7
0
//搜索相同牌
bool CAndroidAIBase::SearchSameCard( BYTE byCardData,BYTE &byIndex1,BYTE &byIndex2 )
{
	//
	byIndex1 = FindIndex(byCardData);
	if( byIndex1 == 0xff ) return false;
	byIndex2 = FindIndex(byCardData,byIndex1+1);
	if( byIndex2 == 0xff ) return false;
	return true;
}
void DetectFishDeth::update_data(vector<vector<Point>> contours)
{
    for (int i = 0; i < num_fish; ++i) {
        fish_Assigned[i] = 0;
    }
    // 没有重叠的情况,目标数量==鱼条数
    if (contours.size() == num_fish) {
        for (int i = 0; i < num_fish; ++i)
        {
            Moments m = moments(contours[i]);
            Point center = Point(m.m10 / m.m00, m.m01 / m.m00);

            //todo:
            //目标身份分配
            int index = FindIndex(center_point, center);

            trajectory[index].insert(trajectory[index].cbegin(), center);
            trajectory[index].pop_back();
            center_point[index] = center;

            nearest_point[index] = get_nearest_ponit(center, contours[i]);

            contour_area[index] = contourArea(contours[i]);
            //cout << index<<": "<<contour_area[index] << endl;
        }
    }
    //重叠的情况
    else if (contours.size() < num_fish) {

        sort(contours.begin(), contours.end(), [](vector<Point> a, vector<Point> b) {
            return contourArea(a) > contourArea(b);
        });

        for (int j = 0; j < contours.size(); ++j) {
            double n = round(contourArea(contours[j]) / avg_area);//重叠区域有几个鱼

            Moments m = moments(contours[j]);
            Point center = Point(m.m10 / m.m00, m.m01 / m.m00);

            for (int i = 0; i < n; ++i) {
                int index = FindIndex(center_point, center);
                trajectory[index].insert(trajectory[index].cbegin(), center);
                trajectory[index].pop_back();
                center_point[index] = center;
                contour_area[index] = contourArea(contours[j]) / n;

                if (n > 1) {
                    nearest_point[index] = -1;
                }
                else {
                    nearest_point[index] = get_nearest_ponit(center, contours[i]);
                }
            }
        }
    }
}
Example #9
0
void TopWindow::EventProc(XWindow& w, XEvent *event)
{
	GuiLock __; 
	Ptr<Ctrl> this_ = this;
	if(event->type == ClientMessage) {
		if(event->xclient.format == 32 && event->xclient.message_type)
			if(event->xclient.message_type == XAtom("WM_PROTOCOLS")) {
				Atom a = event->xclient.data.l[0];
				if(a == XAtom("WM_DELETE_WINDOW") && IsEnabled()) {
					LLOG("DELETE_WINDOW " << Name());
					WhenClose();
					return;
				}
				if(a == XAtom("WM_TAKE_FOCUS")) {
					LLOG("TAKE_FOCUS serial: " << event->xclient.serial);
					Xeventtime = event->xclient.data.l[1];
					TakeFocus();
					return;
				}
				if(a == XAtom("_NET_WM_PING")) {
					XEvent ev = *event;
					ev.xclient.window = Xroot;
					XSendEvent(Xdisplay, Xroot, 0, SubstructureRedirectMask|SubstructureNotifyMask, &ev);
					return;
				}
				LLOG("Unknown WM_PROTOCOLS: " << XAtomName(a));
			}
	}
	else
	if(event->type == PropertyNotify && event->xproperty.atom == XAtom("_NET_WM_STATE")) {
		LLOG("_NET_WM_STATE notify");
		Vector<int> p = GetPropertyInts(GetWindow(), XAtom("_NET_WM_STATE"));
		if(FindIndex(p, (int)XAtom("_NET_WM_STATE_HIDDEN")) >= 0) {
			state = MINIMIZED;
			LLOG("MINIMIZED");
		}
		else
		if(FindIndex(p, (int)XAtom("_NET_WM_STATE_MAXIMIZED_HORZ")) >= 0 &&
		   FindIndex(p, (int)XAtom("_NET_WM_STATE_MAXIMIZED_VERT")) >= 0) {
			state = MAXIMIZED;
			LLOG("MAXIMIZED");
		}
		else {
			state = OVERLAPPED;
			LLOG("OVERLAPPED");
		}
	}
	if(this_) Ctrl::EventProc(w, event);
	if(this_) SyncSizeHints();
}
Example #10
0
File: Ini.cpp Project: CrazyPro/ape
//返回连续的行数
int Ini::GetContinueDataNum(char *index)
{
	//__ENTER_FUNCTION

	int num=0;
	int n=FindIndex(index);
	n=GotoNextLine(n);
	while(1)
	{
		if( m_strData[n] == '\r' || m_strData[n] == EOF || m_strData[n] == -3 || m_strData[n] == ' ' || m_strData[n] == '/' || m_strData[n] == '\t' || m_strData[n] == '\n' )
		{
			return num;
		}
		else
		{
			num++;
			n=GotoNextLine(n);
			if( n >= m_lDataLen ) return num;
		}
	}

	//__LEAVE_FUNCTION

//	return 0 ;
}
//*******************************************************************************
BOOL CBCGPDiagramVisualContainer::Remove (CBCGPDiagramItemID id, BOOL bRebuildContainer)
{
	CBCGPBaseVisualObject* pObject = GetItem (id);
	if (pObject == NULL)
	{
		return FALSE;
	}

	ASSERT_VALID(pObject);

	int nIndex = FindIndex (pObject);
	if (nIndex >= 0 && nIndex < (int) m_arObjects.GetSize ())
	{
		m_arObjects[nIndex] = NULL;
	}

	OnRemove (pObject);

	if (pObject->IsAutoDestroy ())
	{
		delete pObject;
	}

	if (bRebuildContainer)
	{
		RebuildContainer ();
	}

	AdjustLayout();
	return TRUE;
}
Example #12
0
XMLToolBarFrame &XMLToolBarFrame::DockAt(XMLToolBarCtrl &tb, Point p)
{
	// should not happen, but....
	if(FindIndex(tb) >= 0)
		return *this;
	
	// get dock position
	int dockLine, col;
	bool insert;
	if(!GetDockTarget(tb, p, dockLine, insert, col))
		return *this;

	// if needed, shift all positions to make place for this toolbar line
	if(insert)
	{
		for(int i = 0; i < relativePositions.GetCount(); i++)
			if(relativePositions[i].cy >= dockLine)
				relativePositions[i].cy++;
	}
		
	// docks the toolbar there
	relativePositions.Add(Size(col, dockLine));
	toolBars.Add(&tb);
	toolBarContainer.AddChild(&tb);
	Reposition();
	Layout();
	tb.toolBarPos = Point(relativePositions.Top().cx, relativePositions.Top().cy);
	return *this;
}
Example #13
0
// closes (undocking it) an XMLToolBar from this frame
XMLToolBarFrame &XMLToolBarFrame::Undock(XMLToolBarCtrl &tb)
{
	// if already docked here, just do nothing
	int i = FindIndex(tb);
	if(i < 0)
		return *this;

	// store inside toolbar last docked position
	Size &sz = relativePositions[i];
	toolBars[i]->toolBarPos= Point(sz.cx, sz.cy);
	
	// remove from toolbars and positions list
	toolBars.Remove(i);
	toolBarContainer.RemoveChild(&tb);
	relativePositions.Remove(i);
	
	// signals closed toolbar
	tb.toolBarState = TOOLBAR_CLOSED;
	tb.toolBarFrame = NULL;

	// reposition the frame
	Reposition();
	Layout();
	
	// frees toolbar from pointing here
	return *this;
}
void
DBOptionsAttributes::SetEnumStrings(const std::string &name,
                                    const std::vector<std::string> &values)
{
    int eIndex = FindIndex(name);
    if (eIndex < 0)
        EXCEPTION0(BadDeclareFormatString);

    int numEnums = (int)optEnums.size();
    std::vector<std::string> newList;
    int idx = 0;
    for (int i = 0 ; i < numEnums ; i++)
    {
        if (i == eIndex)
        {
            for (size_t j = 0 ; j < values.size() ; j++)
                newList.push_back(values[j]);
        }
        else
        {
            for (int j = 0 ; j < enumStringsSizes[i] ; j++)
                newList.push_back(enumStrings[idx+j]);
        }
        idx += enumStringsSizes[i];
    }
    enumStrings = newList;
    enumStringsSizes[eIndex] = values.size();
}
Example #15
0
int wxSheetArrayEdge::FindMaxEdgeIndex(int val, int edge_size) const
{
    const int index = FindIndex(val, true);
    if (index < 0) return -1;
    // we know we're inside the 'index' element (or above or below the array)
    //   find which side is closer and if < edge_size return index
    const int diff = abs(GetMax(index) - val);
    const int diff_min = (index > 0) ? abs(GetMax(index-1) - val) : diff+edge_size+1; 

    const int min_diff = wxMin(diff, diff_min);
    if (min_diff > edge_size)
        return -1;
    else if (min_diff == diff)
        return index;
    else if (min_diff == diff_min)
        return index - 1;
    
    return -1;
    
/*   
    // FIXME I wonder if this really makes complete sense? check it...
    // eg. what would happen if size of cell was only 1 pixel, you couldn't resize it?
    if ( GetSize(index) > edge_size )
    {
        // We know that we are in index, test whether we are
        // close enough to lower or upper border, respectively.
        if ( abs(GetMax(index) - val) < edge_size )
            return index;
        else if ( (index > 0) && (val - GetMin(index) < edge_size) )
            return index - 1;
    }

    return -1;
*/    
}
void SortedVectorMapRow<V>::ApplyIncUnsafe(int32_t column_id,
    const void *update) {
  // Go through the array and find column_id
  int32_t vector_idx = FindIndex(column_id);
  V typed_update = *(reinterpret_cast<const V*>(update));
  if (vector_idx != -1) {
    entries_[vector_idx].second += typed_update;

    // Remove vector_idx if vector_idx becomes 0.
    if (entries_[vector_idx].second == V(0)) {
      RemoveOneEntryAndCompact(vector_idx);
      return;
    }

    // Move vector_idx to maintain sorted order.
    bool forward = typed_update <= V(0);
    LinearSearchAndMove(vector_idx, forward);
    return;
  }
  // Add a new entry.
  if (num_entries_ == capacity_) {
    ResetCapacity(capacity_ + K_BLOCK_SIZE_);
  }

  entries_[num_entries_].first = column_id;
  entries_[num_entries_].second = typed_update;
  ++num_entries_;
  // Move new entry to maintain sorted order. Always move backward.
  LinearSearchAndMove(num_entries_ - 1, false);
}
Example #17
0
File: Ini.cpp Project: CrazyPro/ape
//在指定的行读一数据名称
char *Ini::ReadCaption(char *index, int lines, char* str, int size)
{
	//__ENTER_FUNCTION

	char szTmp[512] ;
	memset( szTmp, 0, 512 ) ;
	sprintf( szTmp, "[%s][%s][%d]", m_strFileName, index, lines ) ;

	int n=FindIndex(index);
	//AssertEx( n != -1, szTmp );

	//跳到指定行数
	n=GotoNextLine(n);
	for(int i=0; i<lines; i++)
	{
		if( n<m_lDataLen )
			n=GotoNextLine(n);
	}

	char* ret = ReadDataName(n);
	strncpy( str, ret, size ) ;
	return ret ;

	//__LEAVE_FUNCTION

//	return 0 ;
}
Example #18
0
/*================================================================ 
* 函数名:    GetContinueDataNum
* 参数:      [in] (char *index_name)当前索引名称
* 功能描述:   返回连续的行数
* 返回值:    成功则返回连续的行数, 否则返0
================================================================*/
int CIni::GetContinueDataNum(char *index_name)
{
	int num = 0;
	int data_pos = FindIndex(index_name);
	data_pos = GotoNextLine(data_pos);
	while(1)
	{
		if (m_str_data[data_pos] == '\n'	|| 
			m_str_data[data_pos] == EOF		||
			m_str_data[data_pos] == ' '		|| 
			m_str_data[data_pos] == '/'		||
			m_str_data[data_pos] == '['		||
			m_str_data[data_pos] == '	'	
			)
		{
			return num;
		}
		else
		{
			num++;
			data_pos = GotoNextLine(data_pos);
			if (data_pos >= m_data_length) { return num; }
				
		}
	}
	return num;
}
Example #19
0
File: Ini.cpp Project: CrazyPro/ape
//以普通方式读一字符串数据
char *Ini::ReadText(char *index, char *name, char* str, int size)
{
	//__ENTER_FUNCTION

	char szTmp[512] ;
	memset( szTmp, 0, 512 ) ;
	sprintf( szTmp, "[%s][%s][%s]", m_strFileName, index, name ) ;

	int n=FindIndex(index);
	//AssertEx( n != -1, szTmp );

	if ( n == -1 )
		return NULL;

	int m=FindData(n, name);
	//AssertEx( m != -1, szTmp );
	if ( m == -1 )
		return NULL;

	char* ret = ReadText(m);
	strncpy( str, ret, size ) ;
	return ret ;

	//__LEAVE_FUNCTION

//	return 0 ;
}
Example #20
0
int 
CloseNodes_Add(CloseNodes *close, Node *node)
{
    assert(close != NULL && "NULL CloseNodes pointer");
    assert(node != NULL && "NULL Node pointer");

    Distance distance = Hash_Distance(&close->id, &node->id);
    int i = FindIndex(close->close_nodes, &distance);

    if (i < 0)
        return 0;

    struct CloseNode *close_node = malloc(sizeof(struct CloseNode));
    check_mem(close_node);

    close_node->node = node;
    close_node->distance = distance;

    if (DArray_count(close->close_nodes) < BUCKET_K)
        DArray_push(close->close_nodes, NULL);

    ShiftFrom(close->close_nodes, i);
    DArray_set(close->close_nodes, i, close_node);

    return 0;
error:
    return -1;
}
Example #21
0
void FindLeadIndexReco( int algo, int &lead, int &sec) {

  float eta, phi;

  // calculate dR of all the jets w.r.t. the two electrons
  for( int j=0; j < NumRecoJets; j++ ) {

    if(usingCorrectedCaloJetPt) {
      p[j]  = JetCorPt[algo][j];
      eta = JetCorEta[algo][j];
      phi = JetCorPhi[algo][j];
    }
    else {
      p[j]  = JetRecoPt[algo][j];
      eta = JetRecoEta[algo][j];
      phi = JetRecoPhi[algo][j];
    }

    // protection:
    if( p[j] < 0.001 ) { p[j] = 0.001; break; }

    R1[j] = radius( eta, phi, eMinusEta,  eMinusPhi );
    R2[j] = radius( eta, phi, ePlusEta,  ePlusPhi );
   }
  
  FindIndex( p, R1, R2, lead, sec, NumRecoJets );
}
Example #22
0
	void TorrentFilesModel::ClearEmptyParents (boost::filesystem::path path)
	{
		const auto pos = Path2Node_.find (path);
		if (pos == Path2Node_.end ())
		{
			qWarning () << Q_FUNC_INFO
					<< "unknown path"
					<< path.c_str ();
			return;
		}

		const auto& node = pos->second;
		if (!node->IsEmpty ())
		{
			UpdateSizeGraph (RootNode_);
			return;
		}

		const auto& parentNode = node->GetParent ();

		const auto nodeRow = node->GetRow ();
		const auto& parentIndex = FindIndex (path.branch_path ());
		beginRemoveRows (parentIndex, nodeRow, nodeRow);
		parentNode->EraseChild (parentNode->begin () + nodeRow);
		Path2Node_.erase (pos);
		endRemoveRows ();

		ClearEmptyParents (path.branch_path ());
	}
Example #23
0
/*================================================================ 
* 函数名:     ReadText
* 参数1:      [in]		(int index_name)当前索引名称
* 参数2:      [in]		(int lines)指定的行
* 参数3:	  [in|out]	(const char *default)默认数值
* 功能描述:   在指定的行读一字符串
* 返回值:     成功则返回文本数据, 否则返回默认值
================================================================*/
char *CIni::ReadText(char *index_name, int lines, const char *default_name)
{
	int data_pos = FindIndex(index_name);

	if (ERROR_DATA_POS == data_pos)
		return (char *)default_name;

	// 跳到指定行数
	data_pos = GotoNextLine(data_pos);
	for (int i = 0; i < lines; i++)
	{
		if (data_pos < m_data_length)
			data_pos = GotoNextLine(data_pos);
	}

	// 读数据
	while (data_pos <= m_data_length)
	{
		if (m_str_data[data_pos] == '=')
		{
			data_pos++;
			return LRTrim(ReadText(data_pos));
		}
		if (m_str_data[data_pos] == '\n')
		{
			return (char *)default_name;
		}
		data_pos++;
	}

	return (char *)default_name;
}
void SortedVectorMapRow<V>::ApplyDenseBatchIncUnsafe(
    const void* update_batch, int32_t index_st, int32_t num_updates) {
  const V* typed_updates = reinterpret_cast<const V*>(update_batch);

  // Use ApplyInc individually on each column_id.
  for (int i = 0; i < num_updates; ++i) {
    int32_t col_id = i + index_st;
    int32_t vector_idx = FindIndex(col_id);
    if (vector_idx != -1) {
      entries_[vector_idx].second += typed_updates[i];

      // Remove vector_idx if vector_idx becomes 0.
      if (entries_[vector_idx].second == V(0)) {
	RemoveOneEntryAndCompact(vector_idx);
      }
      continue;
    }
    // Add a new entry.
    if (num_entries_ == capacity_) {
      ResetCapacity(capacity_ + K_BLOCK_SIZE_);
    }

    entries_[num_entries_].first = col_id;
    entries_[num_entries_].second = typed_updates[i];
    ++num_entries_;
  }

  // Global sort.
  std::sort(entries_.get(), entries_.get() + num_entries_,
      [](const Entry<V>& i, const Entry<V>&j) {
      return i.second > j.second; });
}
Example #25
0
/*================================================================ 
* 函数名:    ReadInt
* 参数:      [in] (int index_name)当前索引名称
*             [in] (int lines)指定的行
* 功能描述:   在指定的行读一整数
* 返回值:    成功则返回整形数据, 否则返0
================================================================*/
int CIni::ReadInt(char *index_name, int lines)
{
	int data_pos = FindIndex(index_name);

	//跳到指定行数
	data_pos = GotoNextLine(data_pos);
	for (int i = 0; i < lines; i++)
	{
		if (data_pos < m_data_length)
			data_pos = GotoNextLine(data_pos);
	}

	//读数据
	while (data_pos < m_data_length)
	{
		if (m_str_data[data_pos] == '=')
		{
			data_pos++;
			char *str = LRTrim(ReadText(data_pos));
			int ret = atoi(str);
			free(str);
			return ret;
		}
		if (m_str_data[data_pos] == '\n')
		{
			return ERROR_DATA;
		}
		data_pos++;
	}

	return ERROR_DATA;
}
Example #26
0
void CIni::GetStr(const char* pszIndex, const char* pszKey,
			const char* pszDefault,
			char* szBuf, int nBufLen)
{
	if( pszIndex==NULL||pszKey==NULL|| pszDefault==NULL
		||szBuf==NULL||nBufLen<=0) return ;


	int nIndexPos = 0;
	int nKeyPos = 0;
	int nRet= 0 ;
	char szValueBuf[MAX_VALUE_BUF_LEN]={0};
	 if( (nIndexPos =FindIndex(pszIndex))!=-1)
	 {
		 if( (nKeyPos = FindKey(pszKey, nIndexPos))!=-1)
		 {
			if(GetValue(nKeyPos,szValueBuf,MAX_VALUE_BUF_LEN))
			{
				if(strlen(szValueBuf)<=nBufLen)
					strcpy(szBuf, szValueBuf);
				return;
			}
			
		 }
	 }
	if(strlen(pszDefault)<=nBufLen)
		strcpy(szBuf, pszDefault);
	else
		strcpy(szBuf,"");
}
V SortedVectorMapRow<V>::operator [] (int32_t column_id) const {
  boost::shared_lock<SharedMutex> read_lock(rw_mutex_);
  int32_t vector_idx = FindIndex(column_id);
  if (vector_idx == -1)
    return V(0);
  return entries_[vector_idx].second;
}
Example #28
0
void InitVQ (VECTOR_OF_F_VECTORS *vfv,int numVectors, 
              VECTOR_OF_F_VECTORS *clusterMeans, 
	     VECTOR_OF_F_VECTORS *clusterVars, int numClusters, int seed) {
  int                          index;
  int                          i, j;
  int                          random;
  float                        rmax;
  int                         *indexArray;
  int                          flag;
  srand(seed);
  fflush(stdout);
  indexArray = (int *) calloc (numClusters, sizeof(int));
  for (i = 0; i < numClusters; i++) {
    flag = 1;
    while (flag) {
      random = rand();
      rmax = RAND_MAX;
      index = (int) ((float) (random)/rmax*numVectors);
      index = index;
      flag = (int) FindIndex(indexArray, i-1, index);
      if (!flag) {
	flag = (int) FindMatch(vfv, numVectors, indexArray, i-1, index);
	//	index = (index+5)%numVectors;
	//flag = (int) FindMatch(vfv, numVectors, indexArray, i-1, index);
      }
    }
    for (j = 0; j <vfv[0]->numElements; j++) {
      clusterMeans[i]->array[j] = vfv[index]->array[j];
      clusterVars[i]->array[j] = 1.0;
    }
    indexArray[i] = index;    
  }
  free(indexArray);
}
Example #29
0
bool SortedVectorStore<V>::Inc(int32_t key, V delta, size_t *size) {
  if (delta == V(0)) return true;
  int32_t vector_idx = FindIndex(key);
  // Not found, insert it.
  if (vector_idx == -1) {
    if (num_entries_ == capacity_) {
      *size = capacity_ + kBlockSize;
      return false;
    }
    vector_idx = num_entries_;
    ++num_entries_;
    entries_[vector_idx].first = key;
    entries_[vector_idx].second = delta;

    // move backwards
    LinearSearchAndMove(vector_idx, false);
    return true;
  }

  // Found
  entries_[vector_idx].second += delta;

  if (entries_[vector_idx].second == V(0)) {
    RemoveOneEntryAndCompact(vector_idx);
  }

  return true;
}
Example #30
0
File: Ini.cpp Project: CrazyPro/ape
//加入一个索引
bool Ini::AddIndex(char *index)
{
	//__ENTER_FUNCTION

	char str[256];
	memset(str, 0, 256);
	int n=FindIndex(index);

	if( n == -1 )	//新建索引
	{
		sprintf(str,"\r\n[%s]\r\n",index);
		m_strData = (char *)realloc(m_strData, m_lDataLen+strlen(str));	//重新分配内存
		sprintf(&m_strData[m_lDataLen], "%s", str);
		m_lDataLen+=(long)(strlen(str));

		InitIndex();
		return true;
	}
	
	return false;	//已经存在

	//__LEAVE_FUNCTION

//	return 0 ;
}