コード例 #1
0
	// allocate the record for a specified key
	void *Untyped::Alloc(Key aKey)
	{
		// convert key to a slot
		// (HACK: assume key is already a hash)
		size_t slot = FindSlot(aKey);

		// if the slot is not empty...
		if (slot != EMPTY)
		{
			// return the record
			assert(false);
			return NULL;
		}

		// grow if the database is full
		if (mCount >= mLimit)
			Grow();

		// add a new record
		void *record = AllocRecord(aKey);

		// return the record
		return record;
	}
コード例 #2
0
ファイル: opstring.cpp プロジェクト: prestocore/browser
OP_STATUS OpString8::SetUTF8FromUTF16(const uni_char* aUTF16str, int aLength /*=KAll*/)
{
	if (NULL == aUTF16str)
	{
		Empty();
		return OpStatus::OK;
	}

	if (aLength == KAll)
	{
		aLength = uni_strlen(aUTF16str);
	}

	UTF8Encoder encoder;
	int size = encoder.Measure(aUTF16str, UNICODE_SIZE(aLength));
	encoder.Reset();

	RETURN_IF_ERROR(Grow(size));

	int read_bytes;
	int written = encoder.Convert(aUTF16str, UNICODE_SIZE(aLength), iBuffer, size, &read_bytes);
	iBuffer[written] = 0;
	return OpStatus::OK;
}
コード例 #3
0
ファイル: darray.cpp プロジェクト: cahocachi/DEFCON
int DArray<T>::PutData( const T &newdata )
{
    int freeslot = -1;				 // Find a free space
    
    for ( int a = 0; a < m_arraySize; ++a ) 
	{
		if ( shadow[a] == 0 ) 
		{
			freeslot = a;
			break;
		}
    }
    
    if ( freeslot == -1 )			// Must resize the array
	{			 
		freeslot = m_arraySize;
		Grow();
    }
	    
    array[freeslot] = newdata;
    shadow[freeslot] = 1;
    
    return freeslot;
}
コード例 #4
0
ファイル: tmisc.cpp プロジェクト: zhongshuiyuan/FastCopy-M
BOOL VBuf::AllocBuf(ssize_t _size, ssize_t _max_size, VBuf *_borrowBuf)
{
	if (buf) FreeBuf();

	if (_max_size == 0)
		_max_size = _size;
	maxSize = _max_size;
	borrowBuf = _borrowBuf;

	if (borrowBuf) {
		if (!borrowBuf->Buf() || borrowBuf->MaxSize() < borrowBuf->UsedSize() + maxSize)
			return	FALSE;
		buf = borrowBuf->Buf() + borrowBuf->UsedSize();
		borrowBuf->AddUsedSize(maxSize + PAGE_SIZE);
	}
	else {
	// 1page 分だけ余計に確保(buffer over flow 検出用)
		if (!(buf = (BYTE *)::VirtualAlloc(NULL, maxSize + PAGE_SIZE, MEM_RESERVE, PAGE_READWRITE))) {
			Init();
			return	FALSE;
		}
	}
	return	Grow(_size);
}
コード例 #5
0
void CHXString::Append(const char* pStr, INT32 size)
{
    HX_ASSERT(size >= 0);

    if (size)
    {
        if (m_pRep)
        {
            EnsureUnique();

            int newSize = m_pRep->GetStringSize() + size;

            Grow(newSize + 1);

            strncpy(m_pRep->GetBuffer() + m_pRep->GetStringSize(), pStr, size); /* Flawfinder: ignore */

            m_pRep->GetBuffer()[newSize] = '\0';
            m_pRep->SetStringSize(newSize);
        }
        else
            m_pRep = new CHXStringRep(pStr, size);

    }
}
コード例 #6
0
HRESULT CLR_RT_HeapBlock_XmlNameTable::AddEntry( CLR_RT_HeapBlock_String*& str, CLR_INT32 hashCode )
{
    TINYCLR_HEADER();
    
    CLR_RT_HeapBlock                     newEntryHB;
    CLR_RT_HeapBlock_XmlNameTable_Entry* newEntry;
    CLR_RT_HeapBlock*                    entryHB;

    CLR_INT32                            count;  

    // create a new instance of the Entry object
    TINYCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( newEntryHB, g_CLR_RT_WellKnownTypes.m_XmlNameTable_Entry ));
    
    newEntry = (CLR_RT_HeapBlock_XmlNameTable_Entry*)newEntryHB.Dereference();
    
    // attach it to the front of the bucket
    entryHB = (CLR_RT_HeapBlock*)GetEntries()->GetElement( GetMask() & hashCode );

    newEntry->SetStr( str );
    newEntry->SetHashCode( hashCode );
    newEntry->SetNext( (CLR_RT_HeapBlock_XmlNameTable_Entry*)entryHB->Dereference() );
    
    entryHB->SetObjectReference( newEntry );

    count = GetCount() + 1;
    
    SetCount( count );

    // if we reach the threshold, we'll grow the buckets
    if(count == GetMask())
    {
        Grow();
    }

    TINYCLR_NOCLEANUP();
}
コード例 #7
0
ファイル: Point.hpp プロジェクト: PhilColbert/LK8000
 void Grow(int d) {
   Grow(d, d);
 }
コード例 #8
0
ファイル: LFCommon.cpp プロジェクト: telnykha/VideoA
TLFObjectList* TLFObjectList::Expand()
{
    if (m_Count == m_Capacity)
        Grow();
    return this;
}
コード例 #9
0
HRESULT CDataStream::SetSizeHint(size_t size)
{
    return Grow(size);
}
コード例 #10
0
ファイル: vect.c プロジェクト: NAIT-CNT/CMPE1700.Public
//Add an item to end of Vector.  May call grow.
Vector Add(Vector v, int val)
{
    if(v.size == v.max) v = Grow(v);
    v.store[v.size++]=val;
    return v;
}
コード例 #11
0
ファイル: types2.hpp プロジェクト: Ambrevar/fr_public
 //! pre-allocate storage
 void HintSize(sInt i)
 { sVERIFY(i>=0); Grow(i); }
コード例 #12
0
ファイル: NavMesh.cpp プロジェクト: JeppeNielsen/PocketEngine
void NavMesh::BuildPointsTriangle(int width, int depth, std::function<bool (int, int)> predicate) {
    for (int i=0; i<triangles.size(); i++) {
        delete triangles[i];
    }
    triangles.clear();
    navigation.clear();
    collision.clear();
    trianglesPerVertex.clear();
    
    std::vector<double> outer = {
        0,0,
        (double)width,0,
        0,(double)depth,
        (double)width,(double)depth,
        };
    
    std::vector<int> segments = {
        0,1,
        1,3,
        3,2,
        2,0,
    };
    
    std::vector<double> holes;

    
    int lastPos = width - 1;
    for (int z=0; z<depth; ++z) {
        int unblockPos = 0;
        for (int x=0; x<width; ++x) {
            bool blocked = predicate(x,z);
            //if (blocked) {
            //    AddHole(outer, segments, holes, {(float)x,(float)z}, {1.0f, 1.0f});
            //}
            //continue;
            
            if (!blocked || x == lastPos) {
                int size = x - unblockPos;
                if (x == lastPos ) {
                    size++;
                }
                if (size>0) {
                    AddHole(outer, segments, holes, {(float)unblockPos,(float)z}, {(float)size, 1.0f});
                }
                unblockPos = x + 1;
            }
        }
    }
    
    triangulateio in;
    memset(&in, 0, sizeof(triangulateio));
    in.numberofpoints = (int)outer.size()/2;
    in.pointlist = &outer[0];
    
    in.holelist = &holes[0];
    in.numberofholes = (int)holes.size()/2;
    
    in.segmentlist = &segments[0];
    in.numberofsegments = (int)segments.size()/2;
    
    triangulateio out;
    memset(&out, 0, sizeof(triangulateio));
    
    triangulate("zpnQ", &in, &out, (struct triangulateio *) NULL );
    
    triangles.resize(out.numberoftriangles);
    for (int i=0; i<out.numberoftriangles; i++) {
        triangles[i] = new NavTriangle();
    }
    
    collision.resize(out.numberofpoints);
    trianglesPerVertex.resize(out.numberofpoints);
    
    for (int i=0; i<out.numberofpoints; i++) {
        double* pos = &out.pointlist[i*2];
        collision[i].x = (float)pos[0];
        collision[i].y = (float)pos[1];
    }
    navigation = collision;
    
   
    
    std::cout<<"-------------"<<std::endl;
    for (int i=0; i<out.numberoftriangles; i++) {
        int* triangleIndex = &out.trianglelist[i*3];
        //std::cout<<triangle[0]<<", "<<triangle[1]<<", " <<triangle[2]<<std::endl;
        NavTriangle& tri = *triangles[i];
        tri.corners[0]= triangleIndex[0];
        tri.corners[1]= triangleIndex[1];
        tri.corners[2]= triangleIndex[2];
        
        int* neighbor = &out.neighborlist[i*3];
        
        tri.neighbors[1] = neighbor[0]>=0 ? triangles[neighbor[0]] : 0;
        tri.neighbors[2] = neighbor[1]>=0 ? triangles[neighbor[1]] : 0;
        tri.neighbors[0] = neighbor[2]>=0 ? triangles[neighbor[2]] : 0;
        
        
       // std::cout<<"neightbor"<<std::endl;
       // std::cout<<neighbor[0]<<", "<<neighbor[1]<<", " <<neighbor[2]<<std::endl;
    }
    
    trifree(out.pointlist);
    trifree(out.neighborlist);
    trifree(out.trianglelist);
    
    TrimSmallTriangles();
    Grow(navigation, -0.5f);
    
    version++;
}
コード例 #13
0
ファイル: ezSockets.cpp プロジェクト: Hazzytje/Kyubu
void ezSocketsPacket::WriteData( const char * Info, unsigned int Length )
{
	Grow( Length + Position );
	memcpy( &Data[Position], Info, Length );
	Position += Length;
}
コード例 #14
0
ファイル: ezSockets.cpp プロジェクト: Hazzytje/Kyubu
void ezSocketsPacket::WriteNT( const MString& Info )
{
	Grow( Position + Info.length() + 1 );
	memcpy( &Data[Position], Info.c_str(), Info.length()+1 );
	Position += Info.length()+1;
}
コード例 #15
0
ファイル: ezSockets.cpp プロジェクト: Hazzytje/Kyubu
void ezSocketsPacket::Write4( unsigned long Info )
{
	Grow( Position + 4 );
	*((unsigned long*)(&Data[Position])) = htonl(Info);
	Position += 4;
}
コード例 #16
0
ファイル: ezSockets.cpp プロジェクト: Hazzytje/Kyubu
void ezSocketsPacket::Write2( unsigned short Info )
{
	Grow( Position + 2 );
	*((short*)(&Data[Position])) = htons(Info);
	Position+=2;
}
コード例 #17
0
ファイル: ezSockets.cpp プロジェクト: Hazzytje/Kyubu
void ezSocketsPacket::Write1( unsigned char Info )
{
	Grow( Position + 1 );
	Data[Position++] = Info;
}
コード例 #18
0
ファイル: MinimalArray.hpp プロジェクト: hxdnshx/SolfiskMod
	void Push(const T& val)
	{
		Grow(m_size + 1);
		m_arr[m_size++] = val;
	}
コード例 #19
0
ファイル: MinimalArray.hpp プロジェクト: hxdnshx/SolfiskMod
	MinimalArrayT(int size, IMinimalAllocator *alloc) :
		m_alloc(alloc),
		m_arr(NULL), m_size(0), m_msize(0) {
		Grow(size);
		m_size = size;
	}
コード例 #20
0
 void Resize(int _nRows, int _nCols) { Grow(_nRows, _nCols); }
コード例 #21
0
void Stack::Push(int value)
{
    if (IsFull())
        Grow();
    data[++top] = value;
}
コード例 #22
0
int
nsMsgKeySet::Add(PRInt32 number)
{
  PRInt32 size;
  PRInt32 *head;
  PRInt32 *tail;
  PRInt32 *end;

#ifdef DEBUG_MSGKEYSET
    printf("add %d\n",number);
#endif
    
  size = m_length;
  head = m_data;
  tail = head;
  end = head + size;

  NS_ASSERTION (number >= 0, "can't have negative items");
  if (number < 0)
    return 0;

  /* We're going to modify the set, so invalidate the cache. */
  m_cached_value = -1;

  while (tail < end) {
    if (*tail < 0) {
      /* it's a range */
      PRInt32 from = tail[1];
      PRInt32 to = from + (-(tail[0]));

      if (from <= number && to >= number) {
        /* This number is already present - we don't need to do
           anything. */
        return 0;
      }

      if (to > number) {
        /* We have found the point before which the new number
           should be inserted. */
        break;
      }

      tail += 2;
    } else {
      /* it's a literal */
      if (*tail == number) {
        /* This number is already present - we don't need to do
           anything. */
        return 0;
      }

      if (*tail > number) {
        /* We have found the point before which the new number
           should be inserted. */
        break;
      }

      tail++;
    }
  }

  /* At this point, `tail' points to a position in the set which represents
     a value greater than `new'; or it is at `end'. In the interest of
     avoiding massive duplication of code, simply insert a literal here and
     then run the optimizer.
     */
  int mid = (tail - head); 

  if (m_data_size <= m_length + 1) {
    int endo = end - head;
    if (!Grow()) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    head = m_data;
    end = head + endo;
  }

  if (tail == end) {
    /* at the end */
    /* Add a literal to the end. */
    m_data[m_length++] = number;
  } else {
    /* need to insert (or edit) in the middle */
    PRInt32 i;
    for (i = size; i > mid; i--) {
      m_data[i] = m_data[i-1];
    }
    m_data[i] = number;
    m_length++;
  }

  Optimize();
  return 1;
}
コード例 #23
0
ファイル: mcloop.c プロジェクト: rganti/simulations_exercises
void Mcloop(void)
{
  int i,j,k;
  int NumberAccepted,NumberTrials;
  double RosenbluthFactor,RosenbluthFactorOld,r;
  double BondedEnergyOld,BondedEnergyNew,NonBondedEnergyNew,NonBondedEnergyOld;
  double BondedEnergySum,NonBondedEnergySum,EnergyNormalize,BondedEnergy,NonBondedEnergy;
  FILE *FilePtr;

  FilePtr=fopen("movie.pdb","w");
  InitializePdb(FilePtr);

//   NumberTrials:                               number of attempts to create a chain
//   NumberAccepted:                             number of accepted chains 
//   BondedEnergySum:                            average bonded energy
//   NonBondedEnergySum:                         average non bonded energy
//   EnergyNormalize:                            number of configurations used to compute averages 
//   BondedEnergyOld, BondedEnergyNew:           bonded energy of the old and trial chains
//   NonBondedEnergyOld, NonBondedEnergyNew:    non bonded energy of the old and trial chains
//   RosenbluthFactorOld, RosenbluthFactor:      statistical weight of the old and trial chains.  If random chains are generated, both values are 1.
//   r:                                          end-to-end distance
//   BondedEnergy,NonBondedEnergy:                Bonded and non bonded energy of the  chain 

  // initiallize variables
  RosenbluthFactor=1.0;
  BondedEnergyNew=0.0;
  NonBondedEnergyNew=0.0;
  RosenbluthFactorOld=1.0;
  BondedEnergyOld=0.0;
  NonBondedEnergyOld=0.0;
  NumberTrials=0.0;
  NumberAccepted=0.0;
  BondedEnergySum=0.0;
  NonBondedEnergySum=0.0;
  EnergyNormalize=0.0;
      
  // generate a first chain
  Grow(FALSE,&RosenbluthFactorOld,&BondedEnergyOld,&NonBondedEnergyOld);


  for(j=0;j<ChainLength;j++)
  {
    Positions[j].x=TrialPositions[j].x;
    Positions[j].y=TrialPositions[j].y;
    Positions[j].z=TrialPositions[j].z;
  }

  BondedEnergy=BondedEnergyOld;
  NonBondedEnergy=NonBondedEnergyOld;

  // Initialize the subroutine "Sample" (the subroutine that will sample the average end-to-end distance)
  Sample(INITIALIZE,1.0,1.0);

  // Generate the Markov chain of states
  for(i=0;i<NumberOfSteps;i++)
  {
    if(fmod(i,20) == 0) {
      printf("cycle: %d \n", i);
    }
    for(k=0;k<1000;k++)
    {
      NumberTrials++;
      // retrace old chain
      Grow(TRUE,&RosenbluthFactorOld,&BondedEnergyOld,&NonBondedEnergyOld);
      // create a new chain
      Grow(FALSE,&RosenbluthFactor,&BondedEnergyNew,&NonBondedEnergyNew);

      // If the new chain is accepted, then copy coordinates
      if(RandomNumber()<(RosenbluthFactor/RosenbluthFactorOld))
      {
        NumberAccepted++;
        NonBondedEnergy=NonBondedEnergyNew;
        BondedEnergy=BondedEnergyNew;

        for(j=0;j<ChainLength;j++)
        {
          Positions[j].x=TrialPositions[j].x;
          Positions[j].y=TrialPositions[j].y;
          Positions[j].z=TrialPositions[j].z;
        }
      }
      RosenbluthFactor=1.0;

      // If the simulation is beyond the set number of equilibration steps,
      // sample End-To-End Distance And Average Energies
      if(i>=NumberOfInitializationSteps) 
      {
        r=sqrt(SQR(Positions[ChainLength-1].x-Positions[0].x)+
              SQR(Positions[ChainLength-1].y-Positions[0].y)+
              SQR(Positions[ChainLength-1].z-Positions[0].z));
        Sample(SAMPLE,r,RosenbluthFactor);
        BondedEnergySum+=BondedEnergy;
        NonBondedEnergySum+=NonBondedEnergy;

        // update number of configurations sampled
        EnergyNormalize+=1.0;

        // Periodically write a pdb file containing the particle coordinates
        if(k==0&&(i%5)==0) 
          WritePdb(FilePtr);
      }
    }
  }

  // Call subroutine "Sample" to output the histogram of the end-to-end distance
  Sample(WRITE_RESULTS,1.0,1.0);

  // Output average energies and fraction of accepted chains
  printf("Fraction Accepted           : %f\n", (double)NumberAccepted/(double)NumberTrials ); 
  printf("Average bonded energy       : %f\n",BondedEnergySum/EnergyNormalize);
  printf("Average nonbonded energy    : %f\n",NonBondedEnergySum/EnergyNormalize);

  fclose(FilePtr);
}
コード例 #24
0
ファイル: types2.hpp プロジェクト: Ambrevar/fr_public
 //! indexing
 Type &operator[](sInt i)    
 { sVERIFY(i>=0); Grow(i+1); return Data[i]; }
コード例 #25
0
nsMsgKeySet::nsMsgKeySet(const char* numbers /* , MSG_NewsHost* host */)
{
  PRInt32 *head, *tail, *end;
    MOZ_COUNT_CTOR(nsMsgKeySet);

#ifdef NEWSRC_DOES_HOST_STUFF
  m_host = host;
#endif
  m_cached_value = -1;
  m_cached_value_index = 0;
  m_length = 0;
  m_data_size = 10;
  m_data = (PRInt32 *) PR_Malloc (sizeof (PRInt32) * m_data_size);
  if (!m_data) return;

  head = m_data;
  tail = head;
  end = head + m_data_size;

  if(!numbers) {
    return;
  }

  while (isspace (*numbers)) numbers++;
  while (*numbers) {
    PRInt32 from = 0;
    PRInt32 to;

    if (tail >= end - 4) {
      /* out of room! */
      PRInt32 tailo = tail - head;
      if (!Grow()) {
        PR_FREEIF(m_data);
        return;
      }
      /* data may have been relocated */
      head = m_data;
      tail = head + tailo;
      end = head + m_data_size;
    }

    while (isspace(*numbers)) numbers++;
    if (*numbers && !isdigit(*numbers)) {
      break;      /* illegal character */
    }
    while (isdigit (*numbers)) {
      from = (from * 10) + (*numbers++ - '0');
    }
    while (isspace(*numbers)) numbers++;
    if (*numbers != '-') {
      to = from;
    } else {
      to = 0;
      numbers++;
      while (*numbers >= '0' && *numbers <= '9')
        to = (to * 10) + (*numbers++ - '0');
      while (isspace(*numbers)) numbers++;
    }

    if (to < from) to = from; /* illegal */

    /* This is a hack - if the newsrc file specifies a range 1-x as
       being read, we internally pretend that article 0 is read as well.
       (But if only 2-x are read, then 0 is not read.)  This is needed
       because some servers think that article 0 is an article (I think)
       but some news readers (including Netscape 1.1) choke if the .newsrc
       file has lines beginning with 0...   ### */
    if (from == 1) from = 0;

    if (to == from) {
      /* Write it as a literal */
      *tail = from;
      tail++;
    } else /* Write it as a range. */ {
      *tail = -(to - from);
      tail++;
      *tail = from;
      tail++;
    }

    while (*numbers == ',' || isspace(*numbers)) {
      numbers++;
    }
  }

  m_length = tail - head; /* size of data */
}
コード例 #26
0
ファイル: cvector.cpp プロジェクト: dblock/agnes
ICVector<T>& ICVector<T>::SetSize(int new_size) {
  Grow(new_size);
  if (new_size == m_nArrayDim) m_nArrayFill = new_size;  
  return *this;
}
コード例 #27
0
int
nsMsgKeySet::Remove(PRInt32 number)
{
  PRInt32 size;
  PRInt32 *head;
  PRInt32 *tail;
  PRInt32 *end;
#ifdef DEBUG_MSGKEYSET
    printf("remove %d\n",number);
#endif

  size = m_length;
  head = m_data;
  tail = head;
  end = head + size;

  // **** I am not sure this is a right thing to comment the following
  // statements out. The reason for this is due to the implementation of
  // offline save draft and template. We use faked UIDs (negative ids) for
  // offline draft and template in order to distinguish them from real
  // UID. David I need your help here. **** jt

  // PR_ASSERT(number >= 0);
  // if (number < 0) {
  //  return -1;
  /// }

  /* We're going to modify the set, so invalidate the cache. */
  m_cached_value = -1;

  while (tail < end) {
    PRInt32 mid = (tail - m_data);

    if (*tail < 0) {
      /* it's a range */
      PRInt32 from = tail[1];
      PRInt32 to = from + (-(tail[0]));

      if (number < from || number > to) {
        /* Not this range */
        tail += 2;
        continue;
      }

      if (to == from + 1) {
        /* If this is a range [N - N+1] and we are removing M
           (which must be either N or N+1) replace it with a
           literal. This reduces the length by 1. */
        m_data[mid] = (number == from ? to : from);
        while (++mid < m_length) {
          m_data[mid] = m_data[mid+1];
        }
        m_length--;
        Optimize();
        return 1;
      } else if (to == from + 2) {
        /* If this is a range [N - N+2] and we are removing M,
           replace it with the literals L,M (that is, either
           (N, N+1), (N, N+2), or (N+1, N+2). The overall
           length remains the same. */
        m_data[mid] = from;
        m_data[mid+1] = to;
        if (from == number) {
          m_data[mid] = from+1;
        } else if (to == number) {
          m_data[mid+1] = to-1;
        }
        Optimize();
        return 1;
      } else if (from == number) {
        /* This number is at the beginning of a long range (meaning a
           range which will still be long enough to remain a range.)
           Increase start and reduce length of the range. */
        m_data[mid]++;
        m_data[mid+1]++;
        Optimize();
        return 1;
      } else if (to == number) {
        /* This number is at the end of a long range (meaning a range
           which will still be long enough to remain a range.)
           Just decrease the length of the range. */
        m_data[mid]++;
        Optimize();
        return 1;
      } else {
        /* The number being deleted is in the middle of a range which
           must be split. This increases overall length by 2.
           */
        PRInt32 i;
        int endo = end - head;
        if (m_data_size - m_length <= 2) {
          if (!Grow()) return NS_ERROR_OUT_OF_MEMORY;
        }
        head = m_data;
        end = head + endo;

        for (i = m_length + 2; i > mid + 2; i--) {
          m_data[i] = m_data[i-2];
        }

        m_data[mid] = (- (number - from - 1));
        m_data[mid+1] = from;
        m_data[mid+2] = (- (to - number - 1));
        m_data[mid+3] = number + 1;
        m_length += 2;

        /* Oops, if we've ended up with a range with a 0 length,
           which is illegal, convert it to a literal, which reduces
           the overall length by 1. */
        if (m_data[mid] == 0) {
          /* first range */
          m_data[mid] = m_data[mid+1];
          for (i = mid + 1; i < m_length; i++) {
            m_data[i] = m_data[i+1];
          }
          m_length--;
        }
        if (m_data[mid+2] == 0) {
          /* second range */
          m_data[mid+2] = m_data[mid+3];
          for (i = mid + 3; i < m_length; i++) {
            m_data[i] = m_data[i+1];
          }
          m_length--;
        }
        Optimize();
        return 1;
      }
    } else {
      /* it's a literal */
      if (*tail != number) {
        /* Not this literal */
        tail++;
        continue;
      }

      /* Excise this literal. */
      m_length--;
      while (mid < m_length) {
        m_data[mid] = m_data[mid+1];
        mid++;
      }
      Optimize();
      return 1;
    }
  }

  /* It wasn't here at all. */
  return 0;
}
コード例 #28
0
ファイル: DynArray.cpp プロジェクト: saurabhd14/tinyos-1.x
void CDynArray::Add(int i){
	if(iSize >= iCapacity)
		Grow();
	ppvArray[iSize] = i;
	iSize++;
}
コード例 #29
0
ファイル: Nixin_SpriteBuffer.cpp プロジェクト: Bonnn/Nixin
//
// End
//
void Nixin::SpriteBuffer::End( Canvas& canvas )
{
	// Check for validity of end call.
	if( !hasBegun )
	{
		Debug::FatalError( "End was called before begin." );
	}


	// Unmap the buffer data pointer, because we're about to draw with it.
    spriteDataBuffer.Unmap( GL_ARRAY_BUFFER );

	// Use custom shader.
    gl->glUseProgram( shader->GetID() );

	// Set the projection matrix, and vertex attributes in the shader.
    shader->SetUniform( "projection", UniformMatrix( canvas.camera.GetProjectionMatrix() ) );
    shader->SetAttribute( "vertexPosition", 3, GL_FALSE, GL_FLOAT, 0, 0 );
    shader->SetAttribute( "texCoords", 2, GL_FALSE, GL_FLOAT, 0, 12 * maxSpriteCount * sizeof( float ) );
    shader->SetAttribute( "tint", 4, GL_FALSE, GL_FLOAT, 0, 20 * maxSpriteCount * sizeof( float ) );

	// Sort sprites.
	if( spriteSortMode != SpriteSortMode::NO_SORTING )
	{
		// Prepared for drawing.
		SortSprites();
		OrderIndices();
	}

	if( drawingMode == SpriteDrawingMode::DEPTH_TESTED )
	{
		canvas.EnableDepthTesting();
	}

	// This will be the total number of sprites draw.
	int	count = 0;
	// While we haven't drawn all the sprites.
	while( count < sprites.size() )			
	{
		// We assume that at least one sprite is going to be drawn this loop.
		int				drawCount = 1;					

		// Set the texture sampler.
        shader->SetUniform<UniformSampler2D>( "spriteTexture", UniformSampler2D( sprites[count].texture, GL_TEXTURE0, false ) );

		// We step through the buffer, looking for a change in texture. If we find one, then take all the sprites that are next to each, that also have the same texture.
		for( int i = count + 1; i < sprites.size(); i++ )
		{
			if( sprites[count].texture == sprites[i].texture )
			{
				drawCount++;
			}
			else
			{
				break;
			}
		}

		// Finally, draw this group of sprites.
        gl->glDrawRangeElements( GL_TRIANGLES, NULL + count  * indicesPerSprite * sizeof( unsigned int ), NULL + count  * indicesPerSprite * sizeof( unsigned int ) + indicesPerSprite * drawCount, indicesPerSprite * drawCount, GL_UNSIGNED_INT, ( GLvoid* )( NULL + count  * indicesPerSprite * sizeof( unsigned int ) ) );

		// Increase the number of sprites drawn.
		count += drawCount;
	} 
	if( drawingMode == SpriteDrawingMode::DEPTH_TESTED )
	{
		canvas.DisableDepthTesting();
	}

	// Check if the sprite buffer needs to grow.
	if( growNextEnd )
	{
		Grow( 2.0f );

		// Set this to false, as the growing is complete.
		growNextEnd = false;
	}
	else
	{
		//glInvalidateBufferData( spriteBuffer->spriteDataBufferLocation );
        spriteDataBuffer.SetData( GL_ARRAY_BUFFER, sizeof( float ) * 36 * maxSpriteCount );
	}

	// Clear the sprite list.
	sprites.clear();

	// No longer drawing.
	hasBegun = false;
}
コード例 #30
0
ファイル: packed-array.cpp プロジェクト: Einkoro/hhvm
ALWAYS_INLINE
ArrayData* PackedArray::ResizeIfNeeded(ArrayData* adIn) {
  if (UNLIKELY(adIn->m_size == adIn->m_packedCap)) return Grow(adIn);
  return adIn;
}