//  Insert  Ref  with hash key  Key  into global  Hash_Table .
//  Ref  represents string  S .
static
void
Hash_Insert(String_Ref_t Ref, uint64 Key, char * S) {
  String_Ref_t  H_Ref;
  char  * T;
  int  Shift;
  unsigned char  Key_Check;
  int64  Ct, Probe, Sub;
  int  i;

  Sub = HASH_FUNCTION (Key);
  Shift = HASH_CHECK_FUNCTION (Key);
  Hash_Check_Array [Sub] |= (((Check_Vector_t) 1) << Shift);
  Key_Check = KEY_CHECK_FUNCTION (Key);
  Probe = PROBE_FUNCTION (Key);

  Ct = 0;
  do {
    for  (i = 0;  i < Hash_Table [Sub] . Entry_Ct;  i ++)
      if  (Hash_Table [Sub] . Check [i] == Key_Check) {
        H_Ref = Hash_Table [Sub] . Entry [i];
        T = Data + String_Start [getStringRefStringNum(H_Ref)] + getStringRefOffset(H_Ref);
        if  (strncmp (S, T, Kmer_Len) == 0) {
          if  (getStringRefLast(H_Ref)) {
            Extra_Ref_Ct ++;
          }
          Next_Ref [(String_Start [getStringRefStringNum(Ref)] + getStringRefOffset(Ref)) / (HASH_KMER_SKIP + 1)] = H_Ref;
          Extra_Ref_Ct ++;
          setStringRefLast(Ref, TRUELY_ZERO);
          Hash_Table [Sub] . Entry [i] = Ref;

          if  (Hash_Table [Sub] . Hits [i] < HIGHEST_KMER_LIMIT)
            Hash_Table [Sub] . Hits [i] ++;

          return;
        }
      }
    if  (i != Hash_Table [Sub] . Entry_Ct) {
      fprintf (stderr, "i = %d  Sub = " F_S64 "  Entry_Ct = %d\n",
               i, Sub, Hash_Table [Sub] . Entry_Ct);
    }
    assert (i == Hash_Table [Sub] . Entry_Ct);
    if  (Hash_Table [Sub] . Entry_Ct < ENTRIES_PER_BUCKET) {
      setStringRefLast(Ref, TRUELY_ONE);
      Hash_Table [Sub] . Entry [i] = Ref;
      Hash_Table [Sub] . Check [i] = Key_Check;
      Hash_Table [Sub] . Entry_Ct ++;
      Hash_Entries ++;
      Hash_Table [Sub] . Hits [i] = 1;
      return;
    }
    Sub = (Sub + Probe) % HASH_TABLE_SIZE;
  }  while  (++ Ct < HASH_TABLE_SIZE);

  fprintf (stderr, "ERROR:  Hash table full\n");
  assert (FALSE);
}
//  Set the  empty  bit to true for the hash table entry
//  corresponding to string  s  whose hash key is  key .
//  Also set global  String_Info . left/right_end_screened
//  true if the entry occurs near the left/right end, resp.,
//  of the string in the hash table.  If not found, add an
//  entry to the hash table and mark it empty.
static
void
Hash_Mark_Empty(uint64 key, char * s) {
  String_Ref_t  h_ref;
  char  * t;
  unsigned char  key_check;
  int64  ct, probe;
  int64  sub;
  int  i, shift;

  sub = HASH_FUNCTION (key);
  key_check = KEY_CHECK_FUNCTION (key);
  probe = PROBE_FUNCTION (key);

  ct = 0;
  do {
    for  (i = 0;  i < Hash_Table [sub] . Entry_Ct;  i ++)
      if  (Hash_Table [sub] . Check [i] == key_check) {
        h_ref = Hash_Table [sub] . Entry [i];
        t = Data + String_Start [getStringRefStringNum(h_ref)] + getStringRefOffset(h_ref);
        if  (strncmp (s, t, Kmer_Len) == 0) {
          if  (! getStringRefEmpty(Hash_Table [sub] . Entry [i]))
            Mark_Screened_Ends_Chain (Hash_Table [sub] . Entry [i]);
          setStringRefEmpty(Hash_Table [sub] . Entry [i], TRUELY_ONE);
          return;
        }
      }
    assert (i == Hash_Table [sub] . Entry_Ct);
    if  (Hash_Table [sub] . Entry_Ct < ENTRIES_PER_BUCKET) {
      // Not found
      if  (Use_Hopeless_Check) {
        Hash_Table [sub] . Entry [i] = Add_Extra_Hash_String (s);
        setStringRefEmpty(Hash_Table [sub] . Entry [i], TRUELY_ONE);
        Hash_Table [sub] . Check [i] = key_check;
        Hash_Table [sub] . Entry_Ct ++;
        Hash_Table [sub] . Hits [i] = 0;
        Hash_Entries ++;
        shift = HASH_CHECK_FUNCTION (key);
        Hash_Check_Array [sub] |= (((Check_Vector_t) 1) << shift);
      }
      return;
    }
    sub = (sub + probe) % HASH_TABLE_SIZE;
  }  while  (++ ct < HASH_TABLE_SIZE);

  fprintf (stderr, "ERROR:  Hash table full\n");
  assert (FALSE);
}
Example #3
0
DISPATCH_VTABLE_INSTANCE(group,
	.do_type = DISPATCH_GROUP_TYPE,
	.do_kind = "group",
	.do_debug = DEBUG_FUNCTION(group, _dispatch_semaphore_debug),
	.do_invoke = NULL,
	.do_probe = NULL,
	.do_dispose = DISPOSE_FUNCTION(group, _dispatch_semaphore_dispose),
);

DISPATCH_VTABLE_INSTANCE(queue,
	.do_type = DISPATCH_QUEUE_TYPE,
	.do_kind = "queue",
	.do_debug = DEBUG_FUNCTION(queue, dispatch_queue_debug),
	.do_invoke = NULL,
	.do_probe = PROBE_FUNCTION(queue, dummy_function_r0),
	.do_dispose = DISPOSE_FUNCTION(queue, _dispatch_queue_dispose),
);

DISPATCH_VTABLE_SUBCLASS_INSTANCE(queue_root, queue,
	.do_type = DISPATCH_QUEUE_GLOBAL_TYPE,
	.do_kind = "global-queue",
	.do_debug = DEBUG_FUNCTION(queue, dispatch_queue_debug),
	.do_invoke = NULL,
	.do_probe = _dispatch_queue_probe_root,
	.do_dispose = NULL,
);

DISPATCH_VTABLE_SUBCLASS_INSTANCE(queue_mgr, queue,
	.do_type = DISPATCH_QUEUE_MGR_TYPE,
	.do_kind = "mgr-queue",