⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signaldictc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Loop through the list until the entry is found *//* Compare actual objects */   register int i;   for (i=0; (i<_count && (_list[i] != obj)); i++);   if (i == _count) {      return NULL_INDEX;   }   return i;}/*-------------------------------------------------------------*/SignalDictCEntry*SignalDictCEntryList::insert(const SignalDictCEntry& obj, unsigned i){/* If this list is sorted, ignore the given index and compute the real one */   if ( sorted ) i = orderOf(obj);/* Otherwise, see if index is valid */   if (i > _count) return (SignalDictCEntry*)NULL;/* Don't allow same address in list twice */   if ( !allow_duplicates && includes(obj) ) return (SignalDictCEntry*)NULL;/* See if there is enough space for another entry */   if ( _count >= _space ) grow();/* Insert entry in position i *//* Make a space for the new entry by moving all others back */   register int	j;   for (j=_count; j>i; j--) {      _list[j] = _list[j-1]; /* Copying objects here */   }   _count++;   SignalDictCEntry	*tp = (SignalDictCEntry *)&obj;/* Copy the object to the list object */   _list[i] = *tp;   return &_list[i];}/*-------------------------------------------------------------*/voidSignalDictCEntryList::remove(unsigned index){   if (index < _count) {      /* Move entries forward in list and overwrite this one */      register int i;      for (i=index+1; i<_count; i++) {	 _list[i-1] = _list[i]; /* Copying objects here */      }      _count--;      if ( autoShrink ) shrink();   }}/*-------------------------------------------------------------*/voidSignalDictCEntryList::remove(const SignalDictCEntry& obj){/* Look up this entry */   register unsigned i = indexOf(obj);   if ( i != NULL_INDEX ) remove(i);}/*-------------------------------------------------------------*//* Return a pointer to the list entry just before this one */SignalDictCEntry*SignalDictCEntryList::before(const SignalDictCEntry& obj) const{/* Look up this entry */   register int i = indexOf(obj);   if ( i == NULL_INDEX || i == 0 ) return (SignalDictCEntry*)NULL;   return &_list[i-1];}/*-------------------------------------------------------------*/unsignedSignalDictCEntryList::orderOf(const SignalDictCEntry& obj) const{/* *  This algorithm is a simple binary search *  If the object is in the list, the index of the object is returned. *  If the object is not in the list, the index where the object would fit *     iN THE SOrting order is returned. *//* Check special cases first */   if ( _count == 0 || obj < _list[0] ) return 0;   if ( obj > _list[_count-1] ) return _count;   int low = 0;   int high = _count - 1;   int mid = 0;   while ( low <= high ) {      mid = (low + high) / 2;      /*int comp = obj.compare(_list[mid]); */      int comp = (obj < _list[mid]) ? -1 : ((obj > _list[mid]) ? 1 : 0);      if ( comp > 0 )		low = mid + 1;      else if (comp == 0)	return mid;      else 			high = mid - 1;   }/* * If the last comparison said the value was greater than the mid, *    then we want to return an index 1 greater than the mid because *    the entry should get inserted after the mid. */   if (low > mid) mid++;   return mid;} /* End SignalDictCEntryList::orderOf *//*-------------------------------------------------------------*/intSignalDictCEntryList::compare(const void *a, const void *b){   SignalDictCEntry *ta = (SignalDictCEntry *)a;   SignalDictCEntry *tb = (SignalDictCEntry *)b;   /* return ta->compare(*tb); */   return (*ta < *tb) ? -1 : ((*ta > *tb) ? 1 : 0);}/*-------------------------------------------------------------*/voidSignalDictCEntryList::sort(){   qsort((void *)_list, (size_t)_count, (size_t)sizeof(SignalDictCEntry),       	 (int (*)(const void*, const void*))compare);}/*-------------------------------------------------------------*/voidSignalDictCEntryList::sort(int (*compar)(const void*, const void*)){   if ( !compar ) return;   qsort((void *)_list, (size_t)_count, (size_t)sizeof(SignalDictCEntry), compar);}/*  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. *                  1315 Dell Avenue *                  Campbell, CA  95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *//* * ODictC.meth -- method definition file for class ODictC * *   This type of list store the members themselves *   PDictC stores only pointers to the members *//* Copy one dictionary to another */SignalDictC&SignalDictC::operator=(const SignalDictC& d){   if ( this != &d ) {      _count = 0;      register int	count = d.size();//// Add each entry in source to destination//      register int i;      for (i=0; i<count; i++) {	 SignalDictCEntry	*e = d[i];	 add(e->key, e->val);      }   }   return *this;}/* Lookup up entries */intSignalDictC::indexOf(const SignalDictCEntry& entry) const{   return SignalDictCEntryList::indexOf(entry);}intSignalDictC::includes(const int& key) const{   return (indexOf(key) != NULL_INDEX);}intSignalDictC::includes(const SignalDictCEntry& entry) const{   return SignalDictCEntryList::includes(entry);}/* Deleting entries */voidSignalDictC::remove(unsigned index){   SignalDictCEntryList::remove(index);}voidSignalDictC::remove(SignalDictCEntry& entry){   SignalDictCEntryList::remove(entry);}/*-------------------------------------------------------------*/intSignalDictC::indexOf(const int& key) const{/* Loop through list, checking keys for a match */   register int i;   for (i=0; i<_count; i++) {/* If this one matches, return the index */      if ( _list[i].key == key ) {	 return i;      }   }   return NULL_INDEX;}/*-------------------------------------------------------------*/SignalCallsC*SignalDictC::definitionOf(const int& key) const{   int	i = indexOf(key); /* Look up this entry */   return ((i==NULL_INDEX) ? (SignalCallsC*)NULL : &_list[i].val);}/*-------------------------------------------------------------*/int&SignalDictC::keyOf(const int index) const{    return _list[index].key;}/*-------------------------------------------------------------*/SignalCallsC&SignalDictC::valOf(const int index) const{    return _list[index].val;}/*-------------------------------------------------------------*/SignalDictCEntry*SignalDictC::entryOf(const int& key) const{   int	i = indexOf(key); /* Get index of key */   return ((i==NULL_INDEX) ? (SignalDictCEntry*)NULL : &_list[i]);}/*-------------------------------------------------------------*/SignalDictCEntry*SignalDictC::add(const int& key, const SignalCallsC& val){/* Check if this entry is already present */   if ( includes(key) ) {      if ( *definitionOf(key) != val ) {         return (SignalDictCEntry*)NULL; /* Same key with different value */      } else {         return entryOf(key);      }   } else { /* Add it */      SignalDictCEntry      ent(key, val);      return append(ent);   }}/*-------------------------------------------------------------*//* Change the definition for this key */SignalDictCEntry*SignalDictC::modify(const int& key, const SignalCallsC& val){   int	i = indexOf(key); /* Look up this entry */   if ( i == NULL_INDEX ) {      return (SignalDictCEntry*)NULL;   } else {      _list[i].val = val; /* Change it */      return &_list[i];   }}/*-------------------------------------------------------------*/SignalDictCEntry*SignalDictC::modify(unsigned index, const SignalCallsC& val){   if (index < _count) {      _list[index].val = val; /* Change it */      return &_list[index];   } else {      return (SignalDictCEntry*)NULL;   }}/*-------------------------------------------------------------*/voidSignalDictC::remove( int& key){   int	i = indexOf(key); /* Look up this entry */   if ( i != NULL_INDEX ) {      SignalDictCEntryList::remove(i);   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -