With classes structured like this, you can easily imagine the method call process. The m_tbl of the object’s class is searched, and if the method was not found, the
m_tbl of super is searched, and so on. If there is no more super, that is to say the method was not found even in Object, then it must not be defined.
The sequential search process in m_tbl is done by search_method().
struct st_table_entry {
unsigned int hash;
char *key;
char *record;
st_table_entry *next;
};
st.c
struct st_hash_type {
int (*compare)(); /*compare为函数指针*/
int (*hash)(); /*hash 为函数指针*/
};
struct st_table {
struct st_hash_type *type;
int num_bins;
int num_entries;
struct st_table_entry **bins;
};
#define EQUAL(table,x,y) ((x)==(y) || (*table->type->compare)((x),(y)) == 0)
#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
#ifdef HASH_LOG
#define COLLISION collision++
#else
#define COLLISION
#endif
#define FIND_ENTRY(table, ptr, hash_val, bin_pos) do {\
bin_pos = hash_val%(table)->num_bins;\
ptr = (table)->bins[bin_pos];\ /*不懂*/
if (PTR_NOT_EQUAL(table, ptr, hash_val, key)) {\
COLLISION;\
while (PTR_NOT_EQUAL(table, ptr->next, hash_val, key)) {\
ptr = ptr->next;\
}\
ptr = ptr->next;\
}\
} while (0)
int
st_lookup(table, key, value)
st_table *table;
register char *key;
char **value;
{
unsigned int hash_val, bin_pos;
register st_table_entry *ptr;
hash_val = do_hash(key, table); /*st.c line68 #define do_hash(key,table) (unsigned int)(*(table)->type->hash)((key)) 不知hash在何处被赋值 */
FIND_ENTRY(table, ptr, hash_val, bin_pos);
if (ptr == 0) {
return 0;
}
else {
if (value != 0) *value = ptr->record;
return 1;
}
}
▼
search_method()
256 static NODE*
257 search_method(klass, id, origin)
258 VALUE klass, *origin;
259 ID id;
260 {
261 NODE *body;
262
263 if (!klass) return 0;
264 while (!st_lookup(RCLASS(klass)->m_tbl, id, &body)) {
265 klass = RCLASS(klass)->super;
266 if (!klass) return 0;
267 }
268
269 if (origin) *origin = klass;
270 return body;
271 }
(eval.c)
This function searches the method named id in the class object klass.
RCLASS(value) is the macro doing:
((struct RClass*)(value))
st_lookup() is a function that searches in st_table the value corresponding to a key. If the value is found, the function returns true and puts the found value at the address given in third parameter (&body).
Nevertheless, doing this search each time whatever the circumstances would be too slow. That’s why in reality, once called, a method is cached. So starting from the second time it will be found without following super one by one. This cache and its search will be seen in the 15th chapter “Methods”.
分享到:
相关推荐
Phonetic Search Methods for Large Speech Databases
### Monte Carlo Tree Search (MCTS) 方法综述 #### 引言 Monte Carlo Tree Search(MCTS)是一种结合了精确树搜索与随机抽样通用性的新型搜索方法。自从提出以来,它在人工智能领域产生了巨大影响,特别是在围棋...
#### 标题:局部方法(Local Methods) #### 描述:网上找到的一个介绍视差的PPT,挺好的。 #### 标签:立体匹配局部方法(stereo match Local Methods) #### 部分内容:LocalMethodsMichaelBleyer LVAStereoVision ...
清晰 彩色 When most people hear “Machine Learning,” they picture a robot: a dependable butler or a deadly Terminator depending on who you ask. But Machine Learning is not ...to voice search.
Open Source Intelligence Methods and Tools focuses on building a deep understanding of how to exploit open source intelligence (OSINT) techniques, methods, and tools to acquire information from ...
Harness the power of Elastic... Different Methods of Search and Bulk Operations Chapter 8. Controlling Relevancy Chapter 9. Cluster Scaling in Production Deployments Chapter 10. Backups and Security
This application-oriented book describes how modern matrix methods can be used to solve these problems, gives an introduction to matrix theory and decompositions, and provides students with a set of ...
Error Correction Coding - Mathematical Methods and Algorithms (Source Files Contained).pdf Error Correction Coding Mathematical Methods and Algorithms Todd K. Moon Utah State University @ E ! C I E N...
The library of T9Search,a Java Library Which provide data analysis methods, data matching method and so on for T9 pinyin search. T9Search = PinyinSearch - QwertySearch If you're looking for other ...
End-to-end Search and Analytics ... Different Methods of Search and Bulk Operations Chapter 8. Controlling Relevancy Chapter 9. Cluster Scaling in Production Deployments Chapter 10. Backups and Security
// getters, setters, and other methods } ``` `@Document`注解指定了索引名称,`@Id`注解标记了主键字段。其他的属性如`name`、`price`和`description`是商品的字段。 然后,创建一个继承自`Elasticsearch...
// getters, setters, and other methods } ``` 5. **数据操作** 使用定义的`ElasticsearchRepository`接口进行CRUD操作,如保存、查找、删除等。 6. **自定义操作** 如果需要更复杂的查询,可以通过实现`...
4. 信赖域方法和阻尼方法(Trust Region and Damped Methods) 这是一种综合考虑局部模型和实际问题规模的算法。在信赖域方法中,算法首先建立一个局部模型来近似目标函数,然后在该模型的信赖域内进行搜索。阻尼...
查询方法的定义(Defining query methods)包括了查询查找策略、查询创建、属性表达式、特殊参数处理、限制查询结果、流式查询结果以及异步查询结果。这些内容教会开发者如何创建、调整和使用声明式查询方法。创建...
在讨论Galileo信号的混合搜索捕获方法时,首先需要理解BOC(Binary Offset Carrier)调制技术,以及它在新出现的卫星导航系统中的应用。BOC调制技术被提议用于未来的Galileo和现代化的GPS M码信号,其主要目标是与...
MH370飞行路线重建小组成员团队的工作情况。 国防科学家为搜索提供了一系列专业知识:水下声学,卫星通信系统和统计数据处理。
This includes methods for searching, indexing, and managing documents within Elasticsearch. #### X-Pack APIs (Page 71) X-Pack is a set of extensions for Elasticsearch that provide additional ...