MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / insert

Method insert

SRC/matrix/ID.cpp:585–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

583
584
585int
586ID::insert(int x)
587{
588 int middle = 0;
589 int left = 0;
590 int right = sz-1;
591 if (sz != 0) {
592 while (left <= right) {
593 middle = (left + right)/2;
594 double dataMiddle = data[middle];
595 if (x == dataMiddle)
596 return 1; // already there
597 else if (x > dataMiddle)
598 left = middle + 1;
599 else
600 right = middle-1;
601 }
602 }
603
604 // we need to enlarge the array .. see if we can do it
605 // without having to go get more space
606
607 middle = left;
608
609 /*
610 for (int i=middle; i<sz; i++)
611 (*this)[i+1] = (*this)[i];
612 (*this)[i]=middle;
613 return middle;
614 */
615
616 if (sz < arraySize) {
617
618 int i = sz;
619 while (i > middle) {
620 data[i] = data[i-1];
621 i--;
622 }
623 sz++;
624 data[i] = x;
625 return 0;
626 } else {
627 int newArraySize = (sz+1) * 2;
628 int *newData = new (nothrow) int[newArraySize];
629 if (newData != 0) {
630
631 // copy the old
632 for (int ii=0; ii<middle; ii++)
633 newData[ii] = data[ii];
634 newData[middle] = x;
635
636 for (int jj=middle; jj<sz; jj++)
637 newData[jj+1] = data[jj];
638
639 sz++;
640
641 if (data != 0 && fromFree == 0)
642 delete [] data;

Callers 15

addComponentMethod · 0.45
sendIDMethod · 0.45
recvIDMethod · 0.45
sendMatrixMethod · 0.45
recvMatrixMethod · 0.45
sendVectorMethod · 0.45
recvVectorMethod · 0.45

Calls

no outgoing calls

Tested by 1

setUpFunctionsFunction · 0.36