示例#1
0
static PyObject* PyJudyIntSetIter_iternext(PyJudyIntSetIter* iter)
{
	JError_t JError;
	int i;

	if (iter->s->s == 0)
		return 0;

	if (iter->b == 0) {
		i = Judy1First(iter->s->s, &iter->i, &JError);
		iter->b = 1;													
																																																			
		if (i == JERR) {
			judy_set_error(&JError);
			return 0;
		}

		return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)iter->i);
	}

	i = Judy1Next(iter->s->s, &iter->i, &JError);

	if (i == JERR) {
		judy_set_error(&JError);
		return 0;
	}

	if (i == 0)
		return 0;

	return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)iter->i);
}
示例#2
0
 // like from find(key) - search for concrete element
 set_const_iterator_base(Pcvoid_t aArray, Word_t aIndex) : m_Array(aArray)
 {
     if (NULL != m_Array)
     {
         m_Index = aIndex;
         m_End = 0 == Judy1First(m_Array, &m_Index, PJE0) || m_Index != aIndex;
     }
     else
     {
         m_End = true;
     }
 }
示例#3
0
 // like from begin() or end()
 set_const_iterator_base(Pcvoid_t aArray) : m_Array(aArray)
 {
     if (NULL != m_Array)
     {
         m_Index = 0;
         // should not return 0 if m_Array is not NULL
         Judy1First(m_Array, &m_Index, PJE0);
         m_End = false;
     }
     else
     {
         m_End = true;
     }
 }
示例#4
0
unsigned long flx_collector_t::reap ()
{
  unsigned long count = 0;
  Word_t next=(Word_t)NULL;
  int res = Judy1First(j_tmp,&next,&je);
  while(res) {
    delete_frame((void *)(void*)next);
    ++count;
    res = Judy1Next(j_tmp,&next,&je);
  }
  Judy1FreeArray(&j_tmp,&je);
  if(debug) {
    fprintf(stderr,"Reaped %lu objects\n",count);
    fprintf(stderr,"Still allocated %lu objects occupying %lu bytes\n", get_allocation_count(), get_allocation_amt());
  }
  return count;
}
示例#5
0
int
Judy1Dup(PPvoid_t PPDest, Pvoid_t PSource, JError_t * PJError)
{
    Pvoid_t   newJArray = 0;            // new Judy1 array to ppopulate
    Word_t    kindex;                   // Key/index
    int       Ins_rv = 0;               // Insert return value

    for (kindex = 0L, Ins_rv = Judy1First(PSource, &kindex, PJError);
         Ins_rv == 1; Ins_rv = Judy1Next(PSource, &kindex, PJError))
    {
        Ins_rv = Judy1Set(&newJArray, kindex, PJError);
    }
    if (Ins_rv == JERR)
        return Ins_rv;

    *PPDest = newJArray;
    return Ins_rv;
}                                       /*  Judy1Dup */
示例#6
0
文件: tree.c 项目: Pidbip/egtkwave
/*
 * decorated module cleanup (if judy active)
 */
int decorated_module_cleanup(void)
{
#ifdef _WAVE_HAVE_JUDY
if(GLOBALS->sym_tree)
	{
	JudySLFreeArray(&GLOBALS->sym_tree, PJE0);
	}

if(GLOBALS->sym_tree_addresses)
	{
	int rcValue;
	Word_t Index = 0;

	for (rcValue = Judy1First(GLOBALS->sym_tree_addresses, &Index, PJE0); rcValue != 0; rcValue = Judy1Next(GLOBALS->sym_tree_addresses, &Index, PJE0))
        	{
        	((struct tree *)Index)->children_in_gui = 0;
	        }

	Judy1FreeArray(&GLOBALS->sym_tree_addresses, PJE0);
	}

#endif
return(1);
}
示例#7
0
文件: JudyCount.c 项目: DawidvC/felix
FUNCTION Word_t JUDY_EXTERN Judy1Count
#else
FUNCTION Word_t JUDY_EXTERN JudyLCount
#endif
        (
	Pcvoid_t  PArray,	// JRP to first branch/leaf in SM.
	Word_t	  Index1,	// starting Index.
	Word_t	  Index2,	// ending Index.
	PJError_t PJError	// optional, for returning error info.
        )
{
	jpm_t	  fakejpm;	// local temporary for small arrays.
	Pjpm_t	  Pjpm;		// top JPM or local temporary for error info.
	jp_t	  fakejp;	// constructed for calling j__udy1LCountSM().
	Pjp_t	  Pjp;		// JP to pass to j__udy1LCountSM().
	Word_t	  pop1;		// total for the array.
	Word_t	  pop1above1;	// indexes at or above Index1, inclusive.
	Word_t	  pop1above2;	// indexes at or above Index2, exclusive.
	int	  retcode;	// from Judy*First() calls.
JUDYLCODE(PPvoid_t PPvalue);	// from JudyLFirst() calls.


// CHECK FOR SHORTCUTS:
//
// As documented, return C_JERR if the Judy array is empty or Index1 > Index2.

	if ((PArray == (Pvoid_t) NULL) || (Index1 > Index2))
	{
	    JU_SET_ERRNO(PJError, JU_ERRNO_NONE);
	    return(C_JERR);
	}

// If Index1 == Index2, simply check if the specified Index is set; pass
// through the return value from Judy1Test() or JudyLGet() with appropriate
// translations.

	if (Index1 == Index2)
	{
#ifdef JUDY1
	    retcode = Judy1Test(PArray, Index1, PJError);

	    if (retcode == JERRI) return(C_JERR);	// pass through error.

	    if (retcode == 0)
	    {
		JU_SET_ERRNO(PJError, JU_ERRNO_NONE);
		return(C_JERR);
	    }
#else
	    PPvalue = JudyLGet(PArray, Index1, PJError);

	    if (PPvalue == PPJERR) return(C_JERR);	// pass through error.

	    if (PPvalue == (PPvoid_t) NULL)		// Index is not set.
	    {
		JU_SET_ERRNO(PJError, JU_ERRNO_NONE);
		return(C_JERR);
	    }
#endif
	    return(1);					// single index is set.
	}


// CHECK JRP TYPE:
//
// Use an if/then for speed rather than a switch, and put the most common cases
// first.
//
// Note:  Since even cJU_LEAFW types require counting between two Indexes,
// prepare them here for common code below that calls j__udy1LCountSM(), rather
// than handling them even more specially here.

	if (JU_LEAFW_POP0(PArray) < cJU_LEAFW_MAXPOP1) // must be a LEAFW
	{
	    Pjlw_t Pjlw	   = P_JLW(PArray);	// first word of leaf.
	    Pjpm	   = & fakejpm;
	    Pjp		   = & fakejp;
	    Pjp->jp_Addr   = (Word_t) Pjlw;
	    Pjp->jp_Type   = cJU_LEAFW;
	    Pjpm->jpm_Pop0 = Pjlw[0];		// from first word of leaf.
	    pop1	   = Pjpm->jpm_Pop0 + 1;
	}
	else
	{
	    Pjpm = P_JPM(PArray);
	    Pjp	 = &(Pjpm->jpm_JP);
	    pop1 = (Pjpm->jpm_Pop0) + 1;	// note: can roll over to 0.

#if (defined(JUDY1) && (! defined(JU_64BIT)))
	    if (pop1 == 0)		// rare special case of full array:
	    {
		Word_t count = Index2 - Index1 + 1;	// can roll over again.

		if (count == 0)
		{
		    JU_SET_ERRNO(PJError, JU_ERRNO_FULL);
		    return(C_JERR);
		}
		return(count);
	    }
#else
	    assert(pop1);	// JudyL or 64-bit cannot create a full array!
#endif
	}


// COUNT POP1 ABOVE INDEX1, INCLUSIVE:

	assert(pop1);		// just to be safe.

	if (Index1 == 0)	// shortcut, pop1above1 is entire population:
	{
	    pop1above1 = pop1;
	}
	else			// find first valid Index above Index1, if any:
	{
#ifdef JUDY1
	    if ((retcode = Judy1First(PArray, & Index1, PJError)) == JERRI)
		return(C_JERR);			// pass through error.
#else
	    if ((PPvalue = JudyLFirst(PArray, & Index1, PJError)) == PPJERR)
		return(C_JERR);			// pass through error.

	    retcode = (PPvalue != (PPvoid_t) NULL);	// found a next Index.
#endif

// If theres no Index at or above Index1, just return C_JERR (early exit):

	    if (retcode == 0)
	    {
		JU_SET_ERRNO(PJError, JU_ERRNO_NONE);
		return(C_JERR);
	    }

// If a first/next Index was found, call the counting motor starting with that
// known valid Index, meaning the return should be positive, not C_JERR except
// in case of a real error:

	    if ((pop1above1 = j__udy1LCountSM(Pjp, Index1, Pjpm)) == C_JERR)
	    {
		JU_COPY_ERRNO(PJError, Pjpm);	// pass through error.
		return(C_JERR);
	    }
	}


// COUNT POP1 ABOVE INDEX2, EXCLUSIVE, AND RETURN THE DIFFERENCE:
//
// In principle, calculate the ordinal of each Index and take the difference,
// with caution about off-by-one errors due to the specified Indexes being set
// or unset.  In practice:
//
// - The ordinals computed here are inverse ordinals, that is, the populations
//   ABOVE the specified Indexes (Index1 inclusive, Index2 exclusive), so
//   subtract pop1above2 from pop1above1, rather than vice-versa.
//
// - Index1s result already includes a count for Index1 and/or Index2 if
//   either is set, so calculate pop1above2 exclusive of Index2.
//
// TBD:  If Index1 and Index2 fall in the same expanse in the top-state
// branch(es), would it be faster to walk the SM only once, to their divergence
// point, before calling j__udy1LCountSM() or equivalent?  Possibly a non-issue
// if a top-state pop1 becomes stored with each Judy1 array.  Also, consider
// whether the first call of j__udy1LCountSM() fills the cache, for common tree
// branches, for the second call.
//
// As for pop1above1, look for shortcuts for special cases when pop1above2 is
// zero.  Otherwise call the counting "motor".

	    assert(pop1above1);		// just to be safe.

	    if (Index2++ == cJU_ALLONES) return(pop1above1); // Index2 at limit.

#ifdef JUDY1
	    if ((retcode = Judy1First(PArray, & Index2, PJError)) == JERRI)
		return(C_JERR);
#else
	    if ((PPvalue = JudyLFirst(PArray, & Index2, PJError)) == PPJERR)
		return(C_JERR);

	    retcode = (PPvalue != (PPvoid_t) NULL);	// found a next Index.
#endif
	    if (retcode == 0) return(pop1above1);  // no Index above Index2.

// Just as for Index1, j__udy1LCountSM() cannot return 0 (locally == C_JERR)
// except in case of a real error:

	    if ((pop1above2 = j__udy1LCountSM(Pjp, Index2, Pjpm)) == C_JERR)
	    {
		JU_COPY_ERRNO(PJError, Pjpm);		// pass through error.
		return(C_JERR);
	    }

	    if (pop1above1 == pop1above2)
	    {
		JU_SET_ERRNO(PJError, JU_ERRNO_NONE);
		return(C_JERR);
	    }

	    return(pop1above1 - pop1above2);

} // Judy1Count() / JudyLCount()
示例#8
0
void flx_collector_t::mark(pthread::memory_ranges_t *px)
{
  int reclimit = 64;
  if(debug)
    fprintf(stderr,"Collector: Running mark\n");
  assert (root_count == roots.size());
  assert(j_tmp == 0);

  if(px)
  {
    std::vector<pthread::memory_range_t>::iterator end = (*px).end();
    for(
      std::vector<pthread::memory_range_t>::iterator i = (*px).begin();
      i != end;
      ++i
    )
    {
      pthread::memory_range_t range = *i;
      if(debug)
      {
        unsigned long n = (char*)range.e - (char*)range.b;
        fprintf(stderr, "Conservate scan of memory %p->%p, %ld bytes\n",range.b, range.e, n);
      }
      //VALGRIND_MAKE_MEM_DEFINED(range.b, (char*)range.e-(char*)range.b);
      void *end = range.e;
      for ( void *i = range.b; i != end; i = (void*)((void**)i+1))
      {
        if(debug)
          fprintf(stderr, "Check if *%p=%p is a pointer\n",i,*(void**)i);
        scan_object(*(void**)i, reclimit);
      }
      if(debug)
        fprintf(stderr, "DONE: Conservate scan of memory %p->%p\n",range.b, range.e);
    }
  }

  if(debug)
    fprintf(stderr, "Scanning roots\n");
  rootmap_t::iterator const end = roots.end();
  for(
    rootmap_t::iterator i = roots.begin();
    i != end;
    ++i
  )
  {
    if (debug)
      fprintf(stderr, "Scanning root %p\n", (*i).first);
    scan_object((*i).first, reclimit);
  }
  // Now, scan the temporary list until it is empty
  Word_t toscan = 0ul;
  int res = Judy1First(j_tmp,&toscan,&je); // get one object scheduled for scanning
  while(res) {
    Judy1Unset(&j_tmp,toscan,&je);         // remove it immediately
    scan_object((void*)toscan, reclimit);            // scan it, it will either be marked or discarded
    toscan = 0ul;
    res = Judy1First(j_tmp,&toscan,&je); 
  }                                     
  assert(j_tmp == 0);                  

  if(debug)
    fprintf(stderr, "Done Scanning roots\n");
}
示例#9
0
static PyObject* PyJudyIntSet_repr(PyJudyIntSet* set)
{
	if (!set->allow_print)
		return PyString_FromFormat("<%s object at %p>", Py_TYPE(set)->tp_name, (void*)set);

	char s_buffer[32];
	PyObject* retval = 0;
	PyObject* comma_space = 0;
	PyObject* s = 0;

	if (set->s == 0)
		return PyString_FromString("JudyIntSet([])");

	if ((comma_space = PyString_FromString(", ")) == 0)
		goto cleanup;

	retval = PyString_FromString("JudyIntSet([");

	if (retval == 0)
		goto cleanup;

	JError_t JError;
	Word_t v = 0;
	Judy1First(set->s, &v, &JError);

	sprintf(s_buffer, "%llu", (unsigned long long)v);
	s = PyString_FromString(s_buffer);

	if (s == 0) {
		Py_CLEAR(retval);
		goto cleanup;
	}

	PyString_ConcatAndDel(&retval, s);

	if (retval == 0)
		goto cleanup;

	while (1) {
		int i = Judy1Next(set->s, &v, &JError);

		if (i == 0)
			break;

		PyString_Concat(&retval, comma_space);

		if (retval == 0)
			goto cleanup;

		sprintf(s_buffer, "%llu", (unsigned long long)v);
		s = PyString_FromString(s_buffer);

		if (s == 0) {
			Py_CLEAR(retval);
			goto cleanup;
		}

		PyString_ConcatAndDel(&retval, s);

		if (retval == 0)
			goto cleanup;
	}

	s = PyString_FromString("])");

	if (s == 0)
		goto cleanup;

	PyString_ConcatAndDel(&retval, s);

cleanup:

	Py_XDECREF(comma_space);

	return retval;
}
示例#10
0
文件: client.c 项目: anhdocphys/ugh
int ugh_client_send(ugh_client_t *c, int status)
{
#if 0
	if (0 == c->content_type.size)
	{
		c->content_type.size = sizeof("text/plain") - 1;
		c->content_type.data = "text/plain";
	}
#endif

	size_t i;

	for (i = 0; i < ugh_module_handles_size; ++i)
	{
		c->bufs_sumlen += c->bufs[i].size;
	}

	c->buf_send.data = (char *) aux_pool_nalloc(c->pool, UGH_HEADER_BUF);
	c->buf_send.size = snprintf(c->buf_send.data, UGH_HEADER_BUF,
		"HTTP/1.1 %s"              CRLF
		"Server: ugh/"UGH_VERSION  CRLF
		"Content-Length: %"PRIuMAX CRLF
		"Connection: close"        CRLF
		/* "Content-Type: %.*s"       CRLF */
		, ugh_status_header[status]
		, (uintmax_t) c->bufs_sumlen
		/* , (int) c->content_type.size, c->content_type.data */
	);

	void **vptr;
	Word_t idx = 0;

	for (vptr = JudyLFirst(c->headers_out_hash, &idx, PJE0); vptr; vptr = JudyLNext(c->headers_out_hash, &idx, PJE0))
	{
		ugh_header_t *h = *vptr;

		c->buf_send.size += snprintf(c->buf_send.data + c->buf_send.size, UGH_HEADER_BUF - c->buf_send.size,
			"%.*s: %.*s" CRLF, (int) h->key.size, h->key.data, (int) h->value.size, h->value.data);
	}

#if 0
	if (0 != c->location.size)
	{
		c->buf_send.size += snprintf(c->buf_send.data + c->buf_send.size, UGH_HEADER_BUF - c->buf_send.size,
			"Location: %.*s" CRLF, (int) c->location.size, c->location.data);
	}
#endif

	int rc;
	idx = 0;

	for (rc = Judy1First(c->cookies_out_hash, &idx, PJE0); rc; rc = Judy1Next(c->cookies_out_hash, &idx, PJE0))
	{
		strp cookie = (strp) idx;

		c->buf_send.size += snprintf(c->buf_send.data + c->buf_send.size, UGH_HEADER_BUF - c->buf_send.size,
			"Set-Cookie: %.*s" CRLF, (int) cookie->size, cookie->data);
	}

	c->buf_send.size += snprintf(c->buf_send.data + c->buf_send.size, UGH_HEADER_BUF - c->buf_send.size, CRLF);

	log_notice("access %s:%u '%.*s%s%.*s' %.*s %"PRIuMAX, inet_ntoa(c->addr.sin_addr), ntohs(c->addr.sin_port), (int) c->uri.size, c->uri.data,
		c->args.size ? "?" : "", (int) c->args.size, c->args.data, 3, ugh_status_header[status],
		(uintmax_t) c->bufs_sumlen);

	ev_io_start(loop, &c->wev_send);

	return 0;
}