当前位置:网站首页>简单手动实现Map
简单手动实现Map
2022-07-27 19:00:00 【鬼罚olo】
package redisprc.test;
import java.util.*;
/** * @Author lijiaxin * @Description TODO * @Date 2022/07/27/15:55 * @Version 1.0 */
public class myMap<K, V> {
private Node<K,V>[] nodes;
private int size;
private static class Node<K,V> {
K key;
V value;
Node(K key,V value){
this.key = key;
this.value = value;
}
}
public void put(K key,V value){
if(nodes == null){
nodes = new Node[10];
}
int index = indexOfkey(key);
if (index!=-1){
nodes[index].value = value;
}else {
nodes[size] = new Node<K, V>(key,value);
size++;
}
}
private int indexOfkey(K key){
for (int index = 0; index < size; index++) {
if (key.equals(this.nodes[index].key)){
return index;
}
}
return -1;
}
public V get(K key){
int index = indexOfkey(key);
if (index!=-1){
return nodes[index].value;
}
return null;
}
public int size(){
return size;
}
}
边栏推荐
- ACM MM 2022 | 浙大提出:点云分割主动学习新SOTA
- Rust variable characteristics
- app测试定位方式
- 自定义recycleView的删除&移动的动画
- 进程管理 进程的监控与管理 ps/pstree/top/lsof
- Implicit intent
- Sre: Google operation and maintenance decryption
- R language uses dplyr package to perform data aggregation statistics, calculate sliding window statistics, calculate sliding group mean, and merge the generated statistical data into the original data
- In crsctl, the function of displayed home
- “地理-语言”大模型文心ERNIE-GeoL及应用
猜你喜欢

Command line PDF Converter::: fcoder 2PDF

建筑云渲染的应用正在扩大,越来越多的行业急需可视化服务

"Geography language" large model Wenxin Ernie geol and its application

Worthington蘑菇多酚氧化酶的特性及测定方案

LabVIEW learning note 9: capture the "value change" event generated by the program modifying the control value

MobileVIT学习笔记

The solution that the laptop can connect to WiFi but the browser cannot open the web page

University of Tilburg, Federal University of the Netherlands | neural data to text generation based on small datasets: comparing the added value of two semi supervised learning approvals on top of a l

Rust变量特点

C language - Introduction - grammar - pointer (12)
随机推荐
Worthington毒液中核酸外切酶的特征及相关文献
Rust variable characteristics
ECCV 2022 | China University of science and Technology & jd.com proposed: data efficient transformer target detector
QModbus库使用,并作为ROS节点发布话题及程序CMakelist编写
Characteristics and determination scheme of Worthington mushroom polyphenol oxidase
工程技术开发的圈套与局限性
大佬们,mysql版本低,不支持cdc,所以canal同步binlog至kafka,数据同步至cli
“地理-语言”大模型文心ERNIE-GeoL及应用
多人协作开发规范
Pytest失败重跑
Puzzle (002) inner solid, outer solid, Hamilton
基于DSP 回传音通话降噪链路设计
Sre: Google operation and maintenance decryption
Box model and element positioning
Five celebrities' worries about AI
[what subjects does Huawei hcie security test? What knowledge points does Huawei hcie security test have?]
华为成立全球生态发展部:全力推进HMS全球生态建设
In crsctl, the function of displayed home
Dobot magician robot arm - Introduction
Acwing3715. Minimum exchange times (simulation idea of bubble sorting method)