当前位置:网站首页>简单手动实现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;
}
}
边栏推荐
- Process management process monitoring and management ps/pstree/top/lsof
- 中英文说明书丨 AbFluor 488 细胞凋亡检测试剂盒
- Qmodbus library is used, and it is written as ROS node publishing topic and program cmakelist
- Design of noise reduction link based on DSP
- 软件测试面试题:软件验收测试包括正式验收测试、alpha测试、beta测试三种测试?
- [anti shake and throttling]
- ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA
- JVM-内存模型 面试总结
- 报表设计丨如何让你的PowerBI看板出彩?
- PostgreSQL source code (65) analysis of the working principle of globalvis, a new snapshot system
猜你喜欢

Postgresql源码(65)新快照体系Globalvis工作原理分析

Can single mode and multi-mode of industrial switches replace each other?

mysql 最大建议行数2000w,靠谱吗?

zibbix安装部署

新来个技术总监要我做一个 IP 属地功能~

数字化工厂管理系统有哪些价值

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

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

What are the product performances of industrial Ethernet switches?

Instructions - Worthington reverse transcriptase, recombinant HIV testing program
随机推荐
三星最先进EUV产线已投产:今年7nm产能将是去年3倍
综合设计一个OPPE主页--页面的精选配件的设计
软件测试面试题:设计系统测试计划需要参考的项目文档?
R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses deviance function to calculate the sum of squares of residual
首发展锐5G芯片!纯国产5G手机海信F50曝光:搭载虎贲T710+春藤510
Acwing3715. 最少交换次数(冒泡排序法的模拟思路)
美国新宣布制裁的6家中国企业到底是何方神圣?
MobileVIT学习笔记
Design of noise reduction link based on DSP
"Geography language" large model Wenxin Ernie geol and its application
ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA
Force buckle 919. Complete binary tree inserter
Big guys, the MySQL version is low and does not support CDC, so canal synchronizes binlog to Kafka and data to cli
Dual process theory and triple mental model
Five celebrities' worries about AI
Sre related question answering
Thesis appreciation [emnlp18] uses sequence tagging for component parsing
【华为HCIE安全考什么科目?华为HCIE安全考什么知识点?】
软件测试面试题:在windows下保存一个文本文件时会弹出保存对话框,如果为文件名建立测试用例,等价类应该怎样划分?
Implicit intent