使用索引值范围的哈希算法. [英] Hashing algorithm using index value ranges.

查看:128
本文介绍了使用索引值范围的哈希算法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个基于索引值范围而不是单个索引值存储数据的哈希.

这应该有助于解释我的意思:

I''m trying to make a hash that stores data based on a index value range instead of a single index value.

This should help explain what I mean:

________________________________________________<br />
<br />
=== PSEUDO CODE ===<br />
/* function: hash_insert(int lower_bound, int upper_bound, string data); */<br />
<br />
hash_insert(4, 11, "found me!");<br />
hash_insert(16, 19, "where am I?");<br />
<br />
print( hash_find(18) );<br />
print( hash_find(5) );<br />
<br />
=== PROGRAM OUTPUT ===<br />
where am I?<br />
found me!<br />
________________________________________________<br />



值范围没有特定的模式.

我很沮丧有人有线索吗? :((<



There isn''t a particular pattern to the value ranges.

I''m stumped. Does anyone have a clue? :((

推荐答案

取决于潜在条目的数量和范围的大小,您可能会考虑采用蛮力方法:

->为hash_insert(...)范围中的每个数字添加哈希表中的专用条目.

IE. hash_insert(...) 功能是用于多个连续single_hash_insert(...) 呼叫的便捷功能.

听起来可能很傻,但也许可以解决您的问题.

干杯

Andi
Depending on the amount of potential entries and the size of the ranges, you might consider to go a brute-force approach:

--> Add for each number in the hash_insert(...) range a dedicated entry in the hash table.

I.e. the hash_insert(...) function is a convenience function for multiple consecutive single_hash_insert(...) calls.

May sound silly, but maybe it solves your problem.

Cheers

Andi


这是您要找的吗?
它基本上检查写入该函数的数据是否在保存的数据范围内.

Is this what you''re looking for?
It basically checks whether data written to the function falls in range of the saved data.

hash_insert(int lower_bound, int upper_bound, string data)
{
  static int saved_range_lower;
  static int saved_range_upper;
  if (data.Contains("?") == true)
  {
    saved_range_lower = lower_bound;
    saved_range_upper = upper_bound;
  }
  else
  {
    if((lower_bound >= saved_range_lower) &&
       (lower_bound <= saved_range_upper) &&
       (upper_bound >= saved_range_lower) &&
       (upper_bound <= saved_range_upper))
    {
      data = "found me!";
    }
    else
    {
      data = "where am I?"
    }
  }
}


这篇关于使用索引值范围的哈希算法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆