Exemple #1
0
int main() {
  assert(hash_code("gimme") == 477003);
  assert(hash_code("shelter") == 41540041);
  printf("hash_code() passes minimal testing.\n");
  printf("%lu\n", sizeof(unsigned long));
  exit(EXIT_SUCCESS);
}
Exemple #2
0
int main()
{ 
    printf("%d\n", hash_code("abc")); 
    printf("%d\n", hash_code("hello")); 
    printf("%d\n", hash("hello", 10)); 
    return 0;
}
 inline unsigned short hash_code(const cl::tape_inner<Array>& value)
 {
     if (value.is_scalar())
     {
         return hash_code(value.scalar_value_);
     }
     return hash_code(value.array_value_[0]);
 }
Exemple #4
0
void search_buffer(struct search_state *state, const char *pattern,
        int pattern_size, char *buffer, int buffer_size,
        const char *file_name, ullong buffer_offset) {
    const char *buffer_start = buffer;
    /* Where to stop matching */
    const char *buffer_end = buffer + buffer_size - pattern_size;
    int buffer_hash = hash_code(buffer, pattern_size);
    int pattern_hash = state->pattern_hash;
    int most_significant_factor = state->most_significant_factor;

    /* Loop through the buffer... */
    while(buffer < buffer_end) {
        /* Compare hashes, and strings if necessary */
        if(buffer_hash == pattern_hash &&
                !strncmp(buffer, pattern, pattern_size)) {
            print_match(file_name, buffer_offset + (buffer - buffer_start));
        }

        /* Update hash */
        buffer_hash = ((buffer_hash -
                ((unsigned char) *buffer) * most_significant_factor) << 1) +
                (unsigned char) *(buffer + pattern_size);

        buffer++;
    }

    /* Comparison for the last position */
    if(buffer_hash == pattern_hash &&
            !strncmp(buffer, pattern, pattern_size)) {
        print_match(file_name, buffer_offset + (buffer - buffer_start));
    }
}
Exemple #5
0
size_t recorder<Base>::PutPar(const Base &par)
{	static size_t   hash_table[CPPAD_HASH_TABLE_SIZE * CPPAD_MAX_NUM_THREADS];
	size_t          i;
	size_t          code;

	CPPAD_ASSERT_UNKNOWN( 
		thread_offset_ / CPPAD_HASH_TABLE_SIZE
		== 
		thread_alloc::thread_num() 
	);

	// get hash code for this value
	code = static_cast<size_t>( hash_code(par) );
	CPPAD_ASSERT_UNKNOWN( code < CPPAD_HASH_TABLE_SIZE );

	// If we have a match, return the parameter index
	i = hash_table[code + thread_offset_];
	if( i < rec_par_.size() && IdenticalEqualPar(rec_par_[i], par) )
			return i;
	
	// place a new value in the table
	i           = rec_par_.extend(1);
	rec_par_[i] = par;
	CPPAD_ASSERT_UNKNOWN( rec_par_.size() == i + 1 );

	// make the hash code point to this new value
	hash_table[code + thread_offset_] = i;

	// return the parameter index
	return i;
}
void G1StringDedupTable::verify() {
  for (size_t bucket = 0; bucket < _table->_size; bucket++) {
    // Verify entries
    G1StringDedupEntry** entry = _table->bucket(bucket);
    while (*entry != NULL) {
      typeArrayOop value = (*entry)->obj();
      guarantee(value != NULL, "Object must not be NULL");
      guarantee(Universe::heap()->is_in_reserved(value), "Object must be on the heap");
      guarantee(!value->is_forwarded(), "Object must not be forwarded");
      guarantee(value->is_typeArray(), "Object must be a typeArrayOop");
      unsigned int hash = hash_code(value);
      guarantee((*entry)->hash() == hash, "Table entry has inorrect hash");
      guarantee(_table->hash_to_index(hash) == bucket, "Table entry has incorrect index");
      entry = (*entry)->next_addr();
    }

    // Verify that we do not have entries with identical oops or identical arrays.
    // We only need to compare entries in the same bucket. If the same oop or an
    // identical array has been inserted more than once into different/incorrect
    // buckets the verification step above will catch that.
    G1StringDedupEntry** entry1 = _table->bucket(bucket);
    while (*entry1 != NULL) {
      typeArrayOop value1 = (*entry1)->obj();
      G1StringDedupEntry** entry2 = (*entry1)->next_addr();
      while (*entry2 != NULL) {
        typeArrayOop value2 = (*entry2)->obj();
        guarantee(!equals(value1, value2), "Table entries must not have identical arrays");
        entry2 = (*entry2)->next_addr();
      }
      entry1 = (*entry1)->next_addr();
    }
  }
}
Exemple #7
0
size_t optimize_unary_match(
	const CppAD::vector<struct optimize_old_variable>& tape           ,
	size_t                                             current        ,
	size_t                                             npar           ,
	const Base*                                        par            ,
	const CppAD::vector<size_t>&                       hash_table_var ,
	unsigned short&                                    code           )
{	const size_t *arg = tape[current].arg;
	OpCode        op  = tape[current].op;
	size_t new_arg[1];
	
	CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 );
	CPPAD_ASSERT_UNKNOWN( NumRes(op) > 0  );
	CPPAD_ASSERT_UNKNOWN( arg[0] < current );
	new_arg[0] = tape[arg[0]].new_var;
	CPPAD_ASSERT_UNKNOWN( new_arg[0] < current );
	code = hash_code(
		op                  , 
		new_arg             ,
		npar                ,
		par
	);
	size_t  i               = hash_table_var[code];
	CPPAD_ASSERT_UNKNOWN( i < current );
	if( op == tape[i].op )
	{	size_t k = tape[i].arg[0];
		CPPAD_ASSERT_UNKNOWN( k < i );
		if (new_arg[0] == tape[k].new_var )
			return tape[i].new_var;
	}
	return 0;
} 
Exemple #8
0
void DremelWriter::write_string(int fno, char* str, int32_t len, char rep, char def)
{
	assert(levels[fno]);
	assert(datas[fno]);
	char tmp[4];
	tmp[0] = rep;
	tmp[1] = def;
	fwrite(tmp, 2, 1, levels[fno]);
	fwrite(&len, 4, 1, datas[fno]);
	size_t hashcode = hash_code(str);
	fwrite(&hashcode, sizeof(size_t), 1, datas[fno]);

	if (len > 0)
	{
		fwrite(str, len, 1, datas[fno]);
	}

	len++;
	tmp[0] = 0;
	tmp[1] = 0;
	tmp[2] = 0;
	tmp[3] = 0;

	int padding_count = len % 4;
	padding_count++; //null terminal C string
	fwrite(tmp, padding_count, 1, datas[fno]); //one byte for c string end indicator, one for padding
	//cout << fno << "\t" << (int) rep << "\t" << (int) def << "\t" << str << "\n";
}
Exemple #9
0
void DremelWriter::write_string(int fno, string str, char rep, char def)
{
	assert(levels[fno]);
	assert(datas[fno]);
	char tmp[4];
	tmp[0] = rep;
	tmp[1] = def;
	int32_t len = str.length();
	fwrite(tmp, 2, 1, levels[fno]);
	fwrite(&len, 4, 1, datas[fno]);

	size_t hashcode = hash_code(str.c_str());
	fwrite(&hashcode, sizeof(size_t), 1, datas[fno]);

	if (len > 0)
	{
		fwrite(str.c_str(), len, 1, datas[fno]);
	}

	len++;
	tmp[0] = 0;
	tmp[1] = 0;
	tmp[2] = 0;
	tmp[3] = 0;

	int padding_count = len % 4;
	padding_count++; //null terminal C string
	fwrite(tmp, padding_count, 1, datas[fno]); //one byte for c string end indicator, one for padding
}
void G1StringDedupTable::deduplicate(oop java_string, G1StringDedupStat& stat) {
  assert(java_lang_String::is_instance(java_string), "Must be a string");
  NoSafepointVerifier nsv;

  stat.inc_inspected();

  typeArrayOop value = java_lang_String::value(java_string);
  if (value == NULL) {
    // String has no value
    stat.inc_skipped();
    return;
  }

  bool latin1 = java_lang_String::is_latin1(java_string);
  unsigned int hash = 0;

  if (use_java_hash()) {
    // Get hash code from cache
    hash = java_lang_String::hash(java_string);
  }

  if (hash == 0) {
    // Compute hash
    hash = hash_code(value, latin1);
    stat.inc_hashed();

    if (use_java_hash() && hash != 0) {
      // Store hash code in cache
      java_lang_String::set_hash(java_string, hash);
    }
  }

  typeArrayOop existing_value = lookup_or_add(value, latin1, hash);
  if (existing_value == value) {
    // Same value, already known
    stat.inc_known();
    return;
  }

  // Get size of value array
  uintx size_in_bytes = value->size() * HeapWordSize;
  stat.inc_new(size_in_bytes);

  if (existing_value != NULL) {
    // Enqueue the reference to make sure it is kept alive. Concurrent mark might
    // otherwise declare it dead if there are no other strong references to this object.
    G1SATBCardTableModRefBS::enqueue(existing_value);

    // Existing value found, deduplicate string
    java_lang_String::set_value(java_string, existing_value);

    if (G1CollectedHeap::heap()->is_in_young(value)) {
      stat.inc_deduped_young(size_in_bytes);
    } else {
      stat.inc_deduped_old(size_in_bytes);
    }
  }
}
Exemple #11
0
VAL_T Map_get (Map *map, KEY_T key) {
    uint32_t hash = hash_code(key) % map->size;
    struct element *e = &(map->elements[hash]);
    while (e != NULL) {
        if (e->key == key) return e->val;
        e = e->next;
    }
    return VAL_NONE;
}
Exemple #12
0
bool Map_contains_key (Map *map, KEY_T key) {
    uint32_t hash = hash_code(key) % map->size;
    struct element *e = &(map->elements[hash]);
    while (e != NULL) {
        if (e->key == key) return true;
        e = e->next;
    }
    return false;
}
void Dfa::tr_nfa_to_dfa(const Nfa &nfa){
    State start_state;
    closure(nfa.get_start(), start_state, true);
    auto start_hash_code = hash_code(start_state);

    map<HashCodeType, State*> node_set_map;
    map<HashCodeType, Node*> node_map;
    queue<HashCodeType> node_set_queue;
    node_set_map[start_hash_code] = &start_state;
    node_map[start_hash_code] = new Node();
    node_set_queue.push(start_hash_code);

    while(!node_set_queue.empty()){
        auto code_now = node_set_queue.front();
        node_set_queue.pop();
        auto set_now = node_set_map[code_now];
        auto node_now = node_map[code_now];

        for(char path_char=PATH_BEGIN;path_char<PATH_END;++path_char){
            auto set_next = new State();
            next(*set_now, *set_next, path_char);
            if(set_next->size() == 0) continue;
            auto code_next = hash_code(*set_next);

            bool is_new_set = false;
            if(node_map.end() == node_map.find(code_next)){
                node_map[code_next] = new Node(contain_end_node(*set_next));
                node_set_map[code_next] = set_next;
                node_set_queue.push(code_next);
                is_new_set = true;
            }

            auto node_next = node_map[code_next];
            node_now->set_path(node_next, path_char);

            if(!is_new_set){
                safe_delete(set_next);
            }
        }
    }

    _start = node_map[start_hash_code];
}
Exemple #14
0
void wcurses_css( WINDOW *win, char *name, int dir )
{
  int try_again = 1;
  while ( try_again )
  {
    int tmpHash = hash_code( name );
    if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
    {
      fprintf( TraceFP( ), "CSSTRIM:trying to set [%s] style - ", name );
    }
    if ( tmpHash == -1 )
    {
      char *pclass = strrchr( name, '.' );
      if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
      {
        fprintf( TraceFP( ), "undefined, trimming at %p\n", pclass );
      }
      if ( pclass )
      {
        pclass[0] = 0;
      }
      else
      {
        try_again = 0;
      }
    }
    else
    {
      if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
      {
        fprintf( TraceFP( ), "ok (%d)\n", hash_code( name ) );
      }
      curses_w_style( win, hash_code( name ), dir );
      try_again = 0;
    }
  }
  return;
}
Exemple #15
0
bool DirectoryMeta::file_exist( std::string name )
{
    size_t hash = hash_code( name );
    for ( auto & f : this->files_ )
    {
        if ( f->name_hash() == hash  && 
             f->name( ) == name )
        {
            return true;
        }
    }

    return false;
}
Exemple #16
0
int SCEDA_hashmap_remove(SCEDA_HashMap *hmap, void **key, void **value) {
  int i = hash_code(hmap, *key);

  int res = SCEDA_listmap_remove(SCEDA_hashmap_nth_map(hmap, i), key, value);

  if(res == 0) {
    hmap->size--;
    if(4 * hmap->size < hmap->buckets) {
      SCEDA_hashmap_resize(hmap, 1 + hmap->buckets / 2);
    }
  }

  return res;
}
Exemple #17
0
int SCEDA_hashmap_put(SCEDA_HashMap *hmap, const void *key,
		const void *value, void **old_value) {
  int i = hash_code(hmap, key);

  int res = SCEDA_listmap_put(SCEDA_hashmap_nth_map(hmap, i), key, value, old_value);

  if(res == 0) {
    hmap->size++;
    if(hmap->size > hmap->buckets) {
      SCEDA_hashmap_resize(hmap, 1 + 2 * hmap->buckets);
    }
  }

  return res;
}
Exemple #18
0
int table_find(struct HashTable *table, UI a) {
DEBUG("f**k");
	int ta = hash_code(a), ptr;
	for (ptr = table->head[ta]; ptr != -1; ptr = table->next[ptr]) {
		if (table->value[ptr] == a) {
			return ptr;
		}
	}
	
	int tot = table->tot;
	table->next[tot] = table->head[ta];
	table->head[ta] = tot;
	table->value[tot] = a;
	table->tot++;
	return tot;
}
Exemple #19
0
void Map_put (Map *map, KEY_T key, VAL_T val) {
    uint32_t hash = hash_code(key) % map->size;
    struct element *e = &(map->elements[hash]);
    if (e->key != KEY_NONE) {
        while (true) {
            if (e->key == key) {
                // key already in set, overwrite val
                e->val = val;
                return;
            }
            if (e->next == NULL) break;
            e = e->next;
        }
        e->next = malloc (sizeof (struct element));
        e = e->next;
    }
    e->key = key;
    e->val = val;
    e->next = NULL;
}
Exemple #20
0
sptr<DirectoryMeta> DirectoryMeta::get_dir( std::string name )
{
    size_t hash = hash_code( name );

    if ( this->name_hash_ == hash &&
         this->name_ == name )
    {
        return shared_from_this();
    }
    
    for ( auto d : this->children_ )
    {
        if ( d->name_hash_ == hash &&
             d->name_ == name )
        {
            return move_ptr( sptr<DirectoryMeta>( d ) );
        }
    }

    return nullptr;
}
uintx G1StringDedupTable::unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl,
                                            size_t partition_begin,
                                            size_t partition_end,
                                            uint worker_id) {
  uintx removed = 0;
  for (size_t bucket = partition_begin; bucket < partition_end; bucket++) {
    G1StringDedupEntry** entry = _table->bucket(bucket);
    while (*entry != NULL) {
      oop* p = (oop*)(*entry)->obj_addr();
      if (cl->is_alive(*p)) {
        cl->keep_alive(p);
        if (cl->is_resizing()) {
          // We are resizing the table, transfer entry to the new table
          _table->transfer(entry, cl->resized_table());
        } else {
          if (cl->is_rehashing()) {
            // We are rehashing the table, rehash the entry but keep it
            // in the table. We can't transfer entries into the new table
            // at this point since we don't have exclusive access to all
            // destination partitions. finish_rehash() will do a single
            // threaded transfer of all entries.
            typeArrayOop value = (typeArrayOop)*p;
            bool latin1 = (*entry)->latin1();
            unsigned int hash = hash_code(value, latin1);
            (*entry)->set_hash(hash);
          }

          // Move to next entry
          entry = (*entry)->next_addr();
        }
      } else {
        // Not alive, remove entry from table
        _table->remove(entry, worker_id);
        removed++;
      }
    }
  }

  return removed;
}
Exemple #22
0
inline size_t optimize_binary_match(
	const CppAD::vector<struct optimize_old_variable>& tape           ,
	size_t                                             current        ,
	size_t                                             npar           ,
	const Base*                                        par            ,
	const CppAD::vector<size_t>&                       hash_table_var ,
	unsigned short&                                    code           )
{	OpCode        op         = tape[current].op;
	const size_t* arg        = tape[current].arg;
	size_t        new_arg[2];
	bool          parameter[2];

	// initialize return value
	size_t  match_var = 0;

	CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 );
	CPPAD_ASSERT_UNKNOWN( NumRes(op) >  0 );
	switch(op)
	{	// parameter op variable ----------------------------------
		case AddpvOp:
		case MulpvOp:
		case DivpvOp:
		case PowpvOp:
		case SubpvOp:
		// arg[0]
		parameter[0] = true;
		new_arg[0]   = arg[0];
		CPPAD_ASSERT_UNKNOWN( arg[0] < npar );
		// arg[1]
		parameter[1] = false;
		new_arg[1]   = tape[arg[1]].new_var;
		CPPAD_ASSERT_UNKNOWN( arg[1] < current );
		break;

		// variable op parameter -----------------------------------
		case DivvpOp:
		case PowvpOp:
		case SubvpOp:
		// arg[0]
		parameter[0] = false;
		new_arg[0]   = tape[arg[0]].new_var;
		CPPAD_ASSERT_UNKNOWN( arg[0] < current );
		// arg[1]
		parameter[1] = true;
		new_arg[1]   = arg[1];
		CPPAD_ASSERT_UNKNOWN( arg[1] < npar );
		break;

		// variable op variable -----------------------------------
		case AddvvOp:
		case MulvvOp:
		case DivvvOp:
		case PowvvOp:
		case SubvvOp:
		// arg[0]
		parameter[0] = false;
		new_arg[0]   = tape[arg[0]].new_var;
		CPPAD_ASSERT_UNKNOWN( arg[0] < current );
		// arg[1]
		parameter[1] = false;
		new_arg[1]   = tape[arg[1]].new_var;
		CPPAD_ASSERT_UNKNOWN( arg[1] < current );
		break;

		// must be one of the cases above
		default:
		CPPAD_ASSERT_UNKNOWN(false);
	}
	code = hash_code(
		op                  , 
		new_arg             ,
		npar                ,
		par
	);
	size_t  i  = hash_table_var[code];
	CPPAD_ASSERT_UNKNOWN( i < current );
	if( op == tape[i].op )
	{	bool match = true;
		size_t j;
		for(j = 0; j < 2; j++)
		{	size_t k = tape[i].arg[j];
			if( parameter[j] )
			{	CPPAD_ASSERT_UNKNOWN( k < npar );
				match &= IdenticalEqualPar(
					par[ arg[j] ], par[k]
				);
			}
			else
			{	CPPAD_ASSERT_UNKNOWN( k < i );
				match &= (new_arg[j] == tape[k].new_var);
			}
		}
		if( match )
			match_var = tape[i].new_var;
	}
	if( (match_var > 0) | ( (op != AddvvOp) & (op != MulvvOp ) ) )
		return match_var;

	// check for match with argument order switched ----------------------
	CPPAD_ASSERT_UNKNOWN( op == AddvvOp || op == MulvvOp );
	i          = new_arg[0];
	new_arg[0] = new_arg[1];
	new_arg[1] = i;
	unsigned short code_switch = hash_code(
		op                  , 
		new_arg             ,
		npar                ,
		par
	);
	i  = hash_table_var[code_switch];
	CPPAD_ASSERT_UNKNOWN( i < current );
	if( op == tape[i].op )
	{	bool match = true;
		size_t j;
		for(j = 0; j < 2; j++)
		{	size_t k = tape[i].arg[j];
			CPPAD_ASSERT_UNKNOWN( k < i );
			match &= (new_arg[j] == tape[k].new_var);
		}
		if( match )
			match_var = tape[i].new_var;
	}
	return match_var;
} 
  DetectionSet DynVolNN::detect(const ImRGBZ&im,DetectionFilter filter) const 
  {
    SphericalOccupancyMap SOM(im);

    vector<MatchPacket> packets(templates.size());
    TaskBlock proc_templates("proc_templates");
    tbb::concurrent_unordered_set<size_t> checked_templates;
    for(int iter = 0; iter < templates.size(); ++iter)
    {
      proc_templates.add_callee([&,iter]()
				{
				  Timer timer;
				  timer.tic();
				  const DynVolTempl&t = templates.at(iter);
				  packets.at(iter) = MatchPacket(SOM,t,[&](const Mat&t)
								 {
								   size_t hash = hash_code(t);
								   auto r = checked_templates.insert(hash);
								   if(!r.second)
								   {
								     cout << "template duplicate skipped! " <<
								       hash << endl;
								   }
								   return !r.second;
								 });
				  long interval = timer.toc();
				  lock_guard<mutex> l(monitor);
				  performance_times[(t.z_min - min_z)/50] += interval;
				  performance_counts[(t.z_min - min_z)/50] ++;
				});
    }
    proc_templates.execute();
    log_file << safe_printf("info: % checked among % templates",checked_templates.size(),templates.size()) << endl;
    std::sort(packets.begin(),packets.end());
    for(int iter = 0; iter < 1; ++iter, iter *= 2)
    {
      string fn = im.filename;
      for(char&c : fn)
	if(c == '/')
	  c = '_';
      packets.at(iter).log(safe_printf("packet_[%]_[%]_",fn,iter),SOM);
    }

    log_times();
    DetectionSet all_dets;
    TaskBlock take_dets("take_dets");
    int stride = 1;
    for(int yIter = stride/2; yIter < im.rows(); yIter += stride)
      take_dets.add_callee([&,yIter]()
			   {
			     for(int xIter = stride/2; xIter < im.cols(); xIter += stride)
			     {
			       float max_resp = -inf;
			       Rect max_bb;
			       for(auto && packet : packets)
			       {
				 if(packet.bb.size().area() <= 0)
				   continue;
				 
				 if(yIter < packet.r.rows && xIter < packet.r.cols)
				 {
				   float resp = packet.r.at<float>(yIter,xIter);
				   if(resp > max_resp)
				   {
				     max_resp = resp;
				     max_bb   = Rect(Point(xIter,yIter),packet.bb.size());
				   }				   
				 }				 
			       }//end for packet

			       auto det = make_shared<Detection>();
			       det->BB = max_bb;
			       det->resp = max_resp;
			       static mutex m; lock_guard<mutex> l(m);
			       all_dets.push_back(det);	  	
			     }// end for xIter
			   });  	
    take_dets.execute();
    all_dets = sort(all_dets);   
    return (all_dets);
  }
Exemple #24
0
void *SCEDA_hashmap_get(SCEDA_HashMap *hmap, const void *key) {
  int i = hash_code(hmap, key);

  return SCEDA_listmap_get(SCEDA_hashmap_nth_map(hmap, i), key);
}
Exemple #25
0
int SCEDA_hashmap_lookup(SCEDA_HashMap *hmap, void **key, void **value) {
  int i = hash_code(hmap, *key);

  return SCEDA_listmap_lookup(SCEDA_hashmap_nth_map(hmap, i), key, value);
}
Exemple #26
0
struct search_state *search_create(const char *pattern, int pattern_size) {
    struct search_state *state = malloc(sizeof(struct search_state));
    state->pattern_hash = hash_code(pattern, pattern_size);
    state->most_significant_factor = 2 << (pattern_size - 2);
    return state;
}
Exemple #27
0
DirectoryMeta::DirectoryMeta( std::string name )
{
    this->name_ = name;
    this->name_hash_ = hash_code( name );
}
Exemple #28
0
unsigned short local_hash_code(
    OpCode        op      ,
    const addr_t* arg     ,
    size_t        npar    ,
    const Base*   par     )
{   CPPAD_ASSERT_UNKNOWN(
        std::numeric_limits<unsigned short>::max()
        >=
        CPPAD_HASH_TABLE_SIZE
    );
    CPPAD_ASSERT_UNKNOWN( size_t (op) < size_t(NumberOp) );
    CPPAD_ASSERT_UNKNOWN( sizeof(unsigned short) == 2 );
    CPPAD_ASSERT_UNKNOWN( sizeof(addr_t) % 2  == 0 );
    CPPAD_ASSERT_UNKNOWN( sizeof(Base) % 2  == 0 );
    unsigned short op_fac = static_cast<unsigned short> (
        CPPAD_HASH_TABLE_SIZE / static_cast<unsigned short>(NumberOp)
    );
    CPPAD_ASSERT_UNKNOWN( op_fac > 0 );

    // number of shorts per addr_t value
    size_t short_addr_t   = sizeof(addr_t) / 2;

    // initialize with value that separates operators as much as possible
    unsigned short code = static_cast<unsigned short>(
        static_cast<unsigned short>(op) * op_fac
    );

    // now code in the operands
    size_t i;
    const unsigned short* v;

    // first argument
    switch(op)
    {   // Binary operators where first arugment is a parameter.
        // Code parameters by value instead of
        // by index for two reasons. One, it gives better separation.
        // Two, different indices can be same parameter value.
        case AddpvOp:
        case DivpvOp:
        case MulpvOp:
        case PowpvOp:
        case SubpvOp:
        case ZmulpvOp:
        CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 );
        code += hash_code( par[arg[0]] );
        //
        v = reinterpret_cast<const unsigned short*>(arg + 1);
        i = short_addr_t;
        while(i--)
            code += v[i];
        break;

        // Binary operator where first argument is an index and
        // second is a variable (same as both variables).
        case DisOp:

        // Binary operators where both arguments are variables
        case AddvvOp:
        case DivvvOp:
        case MulvvOp:
        case PowvvOp:
        case SubvvOp:
        case ZmulvvOp:
        CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 );
        v = reinterpret_cast<const unsigned short*>(arg + 0);
        i = 2 * short_addr_t;
        while(i--)
            code += v[i];
        break;

        // Binary operators where second arugment is a parameter.
        case DivvpOp:
        case PowvpOp:
        case SubvpOp:
        case ZmulvpOp:
        CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 );
        v = reinterpret_cast<const unsigned short*>(arg + 0);
        i = short_addr_t;
        while(i--)
            code += v[i];
        code += hash_code( par[arg[1]] );
        break;

        // Unary operators
        case AbsOp:
        case AcosOp:
        case AcoshOp:
        case AsinOp:
        case AsinhOp:
        case AtanOp:
        case AtanhOp:
        case CosOp:
        case CoshOp:
        case ErfOp:
        case ExpOp:
        case Expm1Op:
        case LogOp:
        case Log1pOp:
        case SignOp:
        case SinOp:
        case SinhOp:
        case SqrtOp:
        case TanOp:
        case TanhOp:
        CPPAD_ASSERT_UNKNOWN( NumArg(op) == 1 || op == ErfOp );
        v = reinterpret_cast<const unsigned short*>(arg + 0);
        i = short_addr_t;
        while(i--)
            code += v[i];
        break;

        // should have been one of he cases above
        default:
        CPPAD_ASSERT_UNKNOWN(false);
    }

    return code % CPPAD_HASH_TABLE_SIZE;
}
Exemple #29
0
void parse_attributes( char *mono, char *fg, char *bg, int style, char *element )
{
  int mA = 0;
  int fA = default_fg;
  int bA = default_bg;
  int cA = 0;
  int newstyle = hash_code( element );
  if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
  {
    fprintf( TraceFP( ), "CSS(PA):style d=%d / h=%d, e=%s\n", style, newstyle, element );
  }
  parse_either( mono, -3, &mA, 0 );
  parse_either( bg, default_bg, &cA, &bA );
  parse_either( fg, default_fg, &cA, &fA );
  if ( style == -1 )
  {
    if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
    {
      fprintf( TraceFP( ), "CSS(DEF):default_fg=%d, default_bg=%d\n", fA, bA );
    }
    default_fg = fA;
    default_bg = bA;
    default_color_reset = 1;
  }
  else
  {
    if ( fA == -2 )
      bA = -2;
    else
    if ( COLORS )
    {
      if ( COLORS <= fA || COLORS <= bA )
        cA = 0x200000;
      if ( COLORS <= fA )
        fA = __MOD(fA,COLORS);
      if ( COLORS <= bA )
        bA = __MOD(bA,COLORS);
    }
    else
    {
      cA = 0x200000;
      fA = -2;
      bA = -2;
    }
    if ( lynx_has_color && colorPairs < COLOR_PAIRS + -1 && fA != -2 )
    {
      int curPair = 0;
      int iFg = ( fA & ~( fA >> 31 ) ) + 1;
      int iBg = ( bA & ~( bA >> 31 ) ) + 1;
      int iBold = ( cA & 0x200000 ) != 0;
      int iBlink = 0;
      if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
      {
        fprintf( TraceFP( ), "parse_attributes %d/%d %d/%d %#x\n", fA, default_fg, bA, default_bg, cA );
      }
      if ( fA <= 15 && bA <= 15 && ( cA || fA != default_fg || default_bg != bA ) && curPair <= 254 )
      {
        if ( our_pairs[ iBold + iBlink ][0][ iFg ][ iBg ] )
          curPair = our_pairs[ iBold + iBlink ][0][ iFg ][ iBg ];
        else
        {
          colorPairs++;
          curPair = colorPairs;
          init_pair( curPair, fA, bA );
          our_pairs[ iBold + iBlink ][0][ iFg ][ iBg ] = curPair;
        }
      }
      if ( WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
      {
        fprintf( TraceFP( ), "CSS(CURPAIR):%d\n", curPair );
      }
      if ( style <= 132 )
        setStyle( style, cA | ( curPair << 8 ), cA, mA );
      setHashStyle( newstyle, cA | ( curPair << 8 ), cA, mA, element );
    }
    else
    {
      if ( lynx_has_color && fA != -2 && WWW_TraceFlag && ( WWW_TraceMask & 2 ) )
Exemple #30
0
FileMeta::FileMeta( std::string name )
{
    this->name_ = name;
    this->name_hash_ = hash_code( name );
}