Esempio n. 1
0
Cell* Cell::set(int _iIndex, const InternalType* _pIT)
{
    if (_iIndex >= m_iSize)
    {
        return NULL;
    }

    typedef Cell* (Cell::*set_t)(int, const InternalType*);
    Cell* pIT = checkRef(this, (set_t)&Cell::set, _iIndex, _pIT);
    if (pIT != this)
    {
        return pIT;
    }

    if (m_pRealData[_iIndex] != NULL)
    {
        m_pRealData[_iIndex]->DecreaseRef();
        m_pRealData[_iIndex]->killMe();
    }

    const_cast<InternalType*>(_pIT)->IncreaseRef();
    m_pRealData[_iIndex] = const_cast<InternalType*>(_pIT);

    return this;
}
Esempio n. 2
0
Cell* Cell::set(int _iIndex, InternalType* _pIT)
{
    if (_iIndex >= m_iSize)
    {
        return NULL;
    }

    // corner case when inserting twice
    if (m_pRealData[_iIndex] == _pIT)
    {
        return this;
    }

    typedef Cell* (Cell::*set_t)(int, InternalType*);
    Cell* pIT = checkRef(this, (set_t)&Cell::set, _iIndex, _pIT);
    if (pIT != this)
    {
        return pIT;
    }

    if (m_pRealData[_iIndex] != NULL)
    {
        m_pRealData[_iIndex]->DecreaseRef();
        m_pRealData[_iIndex]->killMe();
    }

    _pIT->IncreaseRef();
    m_pRealData[_iIndex] = _pIT;
    return this;
}
Esempio n. 3
0
Cell* Cell::set(InternalType** _pIT)
{
    typedef Cell* (Cell::*set_t)(InternalType**);
    Cell* pIT = checkRef(this, (set_t)&Cell::set, _pIT);
    if (pIT != this)
    {
        return pIT;
    }

    for (int i = 0; i < m_iSize; i++)
    {
        if (i >= m_iSize)
        {
            return NULL;
        }

        if (m_pRealData[i] != NULL)
        {
            m_pRealData[i]->DecreaseRef();
            m_pRealData[i]->killMe();
        }

        _pIT[i]->IncreaseRef();
        m_pRealData[i] = _pIT[i];
    }

    return this;
}
Esempio n. 4
0
SEXP Rf_mkCharLenCE(const char *x, int len, cetype_t enc) {
	JNIEnv *thisenv = getEnv();
	char buf[len + 1];
	memcpy(buf, x, len);
	buf[len] = 0;
	// TODO encoding, assume UTF for now, zero terminated
	SEXP result = (*thisenv)->NewStringUTF(thisenv, buf);
	return checkRef(thisenv, result);
}
Esempio n. 5
0
SEXP Rf_allocVector3(SEXPTYPE t, R_xlen_t len, R_allocator_t* allocator) {
    if (allocator != NULL) {
	unimplemented("RF_allocVector with custom allocator");
	return NULL;
    }
    TRACE(TARG2d, t, len);
    JNIEnv *thisenv = getEnv();
    SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_allocateVectorMethodID, t, len);
    return checkRef(thisenv, result);
}
Esempio n. 6
0
int main()
{
  typedef int T;
  const unsigned int SIZE = 1;
  const unsigned int NUM_ITERATIONS = 1000000;
  std::vector<T> aVec(SIZE);
  std::vector<T>& vecRef = aVec;

  for(unsigned int ii=1; ii< NUM_ITERATIONS; ++ii) {
    aVec.resize(SIZE*2*ii);
    checkRef(aVec, vecRef);
  }

}
Esempio n. 7
0
int main(void){
	int variable = 10;
	int return_value;

	std::cout << "main: " << variable << std::endl;
	std::cout << "main: " << &variable << std::endl;
	checkRef(variable);
	checkConstRef(variable);

	return_value = checkReturnRef(variable);
	std::cout << "return reference: " << return_value << std::endl;
	int &return_value_ref = checkReturnRef(variable);
	std::cout << "return reference: " << return_value_ref << std::endl;

	return 0;
}
Esempio n. 8
0
String* String::set(const char* const* _pstrData)
{
    typedef String* (String::*set_t)(const char * const*);
    String* pIT = checkRef(this, (set_t)&String::set, _pstrData);
    if (pIT != this)
    {
        return pIT;
    }

    for (int i = 0; i < m_iSize; i++)
    {
        if (set(i, _pstrData[i]) == NULL)
        {
            return NULL;
        }
    }
    return this;
}
Esempio n. 9
0
String* String::set(int _iPos, const wchar_t* _pwstData)
{
    if (m_pRealData == NULL || _iPos >= m_iSize)
    {
        return NULL;
    }

    typedef String* (String::*set_t)(int, const wchar_t*);
    String* pIT = checkRef(this, (set_t)&String::set, _iPos, _pwstData);
    if (pIT != this)
    {
        return pIT;
    }

    deleteString(_iPos);
    m_pRealData[_iPos] = copyValue(_pwstData);
    return this;
}
Esempio n. 10
0
String* String::set(const wchar_t* const* _pwstData)
{
    typedef String* (String::*set_t)(const wchar_t * const*);
    String* pIT = checkRef(this, (set_t)&String::set, _pwstData);
    if (pIT != this)
    {
        return pIT;
    }

    for (int i = 0; i < m_iSize; i++)
    {
        if (m_pRealData == NULL || i >= m_iSize)
        {
            return NULL;
        }

        deleteString(i);
        m_pRealData[i] = copyValue(_pwstData[i]);
    }
    return this;
}
Esempio n. 11
0
SEXP SETCDR(SEXP x, SEXP y) {
    JNIEnv *thisenv = getEnv();
    SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, SETCDR_MethodID, x, y);
    return checkRef(thisenv, result);
}
Esempio n. 12
0
SEXP CADR(SEXP e) {
    JNIEnv *thisenv = getEnv();
    SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, CADR_MethodID, e);
    return checkRef(thisenv, result);
}
Esempio n. 13
0
SEXP Rf_cons(SEXP car, SEXP cdr) {
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_consMethodID, car, cdr);
    return checkRef(thisenv, result);
}
Esempio n. 14
0
SEXP Rf_ScalarReal(double value) {
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_ScalarDoubleMethodID, value);
    return checkRef(thisenv, result);
}
Esempio n. 15
0
SEXP Rf_mkChar(const char *x) {
	JNIEnv *thisenv = getEnv();
	// TODO encoding, assume UTF for now
	SEXP result = (*thisenv)->NewStringUTF(thisenv, x);
	return checkRef(thisenv, result);
}
Esempio n. 16
0
SEXP Rf_installChar(SEXP name) {
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, createSymbolMethodID, name);
	return checkRef(thisenv, result);
}
Esempio n. 17
0
SEXP Rf_install(const char *name) {
	JNIEnv *thisenv = getEnv();
	jstring string = (*thisenv)->NewStringUTF(thisenv, name);
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, createSymbolMethodID, string);
	return checkRef(thisenv, result);
}
Esempio n. 18
0
SEXP Rf_duplicate(SEXP x) {
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_duplicateMethodID, x);
	return checkRef(thisenv, result);
}
Esempio n. 19
0
SEXP Rf_getAttrib(SEXP vec, SEXP name) {
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_getAttribMethodID, vec, name);
	return checkRef(thisenv, result);
}
Esempio n. 20
0
SEXP Rf_findVarInFrame(SEXP symbol, SEXP rho) {
	JNIEnv *thisenv = getEnv();
	SEXP result =(*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_findVarInFrameMethodID, symbol, rho);
    return checkRef(thisenv, result);
}
Esempio n. 21
0
SEXP Rf_eval(SEXP expr, SEXP env) {
    JNIEnv *thisenv = getEnv();
    SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_evalMethodID, expr, env);
    return checkRef(thisenv, result);
}
Esempio n. 22
0
SEXP Rf_allocArray(SEXPTYPE t, SEXP dims) {
	TRACE(TARG2d, t, dims);
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_allocateArrayMethodID, t, dims);
	return checkRef(thisenv, result);
}
Esempio n. 23
0
SEXP Rf_ScalarLogical(int value) {
	TRACE(TARG1, value);
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_ScalarLogicalMethodID, value);
    return checkRef(thisenv, result);
}
Esempio n. 24
0
SEXP Rf_ScalarInteger(int value) {
	TRACE("%s(%d)\n", value);
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_ScalarIntegerMethodID, value);
    return checkRef(thisenv, result);
}
Esempio n. 25
0
int main(int argc, char * argv[])
{
  copyArgV = argv;
  int i = 0;
  int c = 0;
  int fd = 0;
  int smallCount = 100000;
  int shortFile = 1;

  if(argc < 2)
  {
    fprintf(stderr, "Invlaid number of Arguments. Exiting Program");
    return 1;
  }
  if (pthread_mutex_init(&mu, NULL) != 0)
  {
    fprintf(stderr, "can't init mutex");
  }

  if (pthread_cond_init(&cv, NULL) != 0)
  {
    fprintf(stderr, "can't init condition variable");
  }
  //finds the smallest file, saves it's index
  for(c = 1; c < argc; c++)
  {
    fd = open(argv[c], O_RDONLY);
    if(fd < 0)
    {
      fprintf(stderr, "Could not open file! Invalid file name. Exiting program\n");
      exit(-1);
    }
    else
    {
      int bufferSize = (int)lseek(fd, 0, SEEK_END);
      if(bufferSize == -1)
      {
        fprintf(stderr, "lseek failed. exiting program\n");
        exit(-1);
      }
      fileSize[c] = bufferSize;
      if(bufferSize < smallCount && bufferSize != 0)
      {
        shortFile = c;
        smallCount = bufferSize;
      }
     } 
  }
  //switch shortest file with first file in argument array
  char * temp = argv[shortFile];
  argv[shortFile] = argv[1];
  argv[1] = temp;
                                              
  int numFile = 1;                                                  
  for(numFile = 1; numFile < argc; numFile++)                       
  {             
    int fd = open(argv[numFile], O_RDONLY); //check if file could be opened
    if(fd < 0)
    {
      fprintf(stderr, "Could not open file. Invalid File name. Exiting program\n");
      exit(-1);
    }
    else
    {
      int bufferSize = (int)lseek((int)fd, 0, SEEK_END);
      if(bufferSize == -1)
      {
      fprintf(stderr, "lseek failed. exiting program\n");
        exit(-1);
      }
      if(lseek(fd, 0 , SEEK_SET) == -1)
      {
      fprintf(stderr, "lseek failed. exiting program\n");
        exit(-1);
      }
      if(bufferSize == 0)
      {
        fprintf(stderr, "Empty file, skipping file. The rest of the files will still be processed.\n");
      }
      else
      {
        //FOR LOAD IMBALANCE. Process shorter files serially, larger threads with multiple threads per file
        if(bufferSize >= 500000)
        {
          //multi threaded
          threadCount = 0; 
          pthread_t pt[MAX_THREADS];
          for(i = 0; i < MAX_THREADS; i++)
          {
            threadInfo  * myThread = malloc(sizeof(threadInfo));
            if(myThread == NULL)
            { 
              fprintf(stderr, "malloc failed, exiting program\n");
              exit(-1);
            }
            myThread -> threadID = i;
            myThread -> filePosition = numFile;

            pthread_create(&pt[i], NULL, work, (void*)myThread);
          }
          int w = 0;
          for(w = 0; w < MAX_THREADS; w++)
          {
            if(pthread_join(pt[w], NULL) != 0)
            {
              fprintf(stderr, "Could not join threads!\n");
            }
          }
         checkThreadRef(numFile);
        }
        else
        {
          //serial
          char buffer[bufferSize];
          read(fd, buffer, bufferSize);                            
          createHash(0, bufferSize, buffer, numFile);     
        }
      }
    }
  }                                                                 
  checkRef(argc);
  createResults();
  int numResults = 0;
  i = 0;
  while(results[i].count != 0)
  {
    i++;
  }
  numResults = i;
  sortResults(numResults);
  printResults();
  return 0;
}
Esempio n. 26
0
SEXP R_NewHashedEnv(SEXP parent, SEXP size) {
	JNIEnv *thisenv = getEnv();
	int sizeAsInt = Rf_asInteger(size);
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, RDataFactoryClass, Rf_NewHashedEnvMethodID, parent, NULL, JNI_TRUE, sizeAsInt);
	return checkRef(thisenv, result);
}
Esempio n. 27
0
SEXP R_FindNamespace(SEXP info) {
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, R_FindNamespaceMethodID, info);
	return checkRef(thisenv, result);
}
Esempio n. 28
0
SEXP GetOption1(SEXP tag)
{
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_GetOption1MethodID, tag);
	return checkRef(thisenv, result);
}
Esempio n. 29
0
SEXP R_ExternalPtrProt(SEXP s) {
	JNIEnv *thisenv = getEnv();
	SEXP result =  (*thisenv)->CallObjectMethod(thisenv, s, externalPtrGetProtMethodID);
    return checkRef(thisenv, result);
}
Esempio n. 30
0
SEXP Rf_allocMatrix(SEXPTYPE mode, int nrow, int ncol) {
	TRACE(TARG2d, mode, nrow, ncol);
	JNIEnv *thisenv = getEnv();
	SEXP result = (*thisenv)->CallStaticObjectMethod(thisenv, CallRFFIHelperClass, Rf_allocateMatrixMethodID, mode, nrow, ncol);
	return checkRef(thisenv, result);
}