HashMap构造函数

news2025/3/1 8:13:16

HashMap()

/**
 * Constructs an empty <tt>HashMap</tt> with the default initial capacity
 * (16) and the default load factor (0.75).
 * 这是一个默认的构造方法,初始化的容量大小是16,装填因子是0.75
 * a 装填因子
 * n 关键字个数
 * m 总容量
 * a = n/m
 * 这里的容量大小为16,装填因子是0.75,就表示当内容达到12个的时候就会可能出现Hash冲突
 * 必须在 "冲突的机会"与"空间利用率"之间寻找一种平衡与折衷.这种平衡与折衷本质上是数据 * 结构中有名的"时-空"矛盾的平衡与折衷.也就是说在空间与时间上
 */
public HashMap() {
    this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted
}

HashMap(int initialCapacity)

 /**
 * Constructs an empty <tt>HashMap</tt> with the specified initial
 * capacity and the default load factor (0.75).
 *
 * @param  initialCapacity the initial capacity.
 * @throws IllegalArgumentException if the initial capacity is negative.
 */
public HashMap(int initialCapacity) {
    this(initialCapacity, DEFAULT_LOAD_FACTOR);
}

HashMap(int initialCapacity, float loadFactor)

/**
 * Constructs an empty <tt>HashMap</tt> with the specified initial
 * capacity and load factor.
 * 指定容量指定装填因子
 * @param  initialCapacity the initial capacity
 * @param  loadFactor      the load factor
 * @throws IllegalArgumentException if the initial capacity is negative
 *         or the load factor is nonpositive
 */
public HashMap(int initialCapacity, float loadFactor) {
    //如果初始化容量小于零
    if (initialCapacity < 0)
        throw new IllegalArgumentException("Illegal initial capacity: " +
                                           initialCapacity);
    //如果初始化容量大于 1 << 30 左移表示乘以多少个 2 ,也就是表示 2的30次方;
    if (initialCapacity > MAXIMUM_CAPACITY)
        initialCapacity = MAXIMUM_CAPACITY;
    //如果装填因子小于等于0
    if (loadFactor <= 0 || Float.isNaN(loadFactor))
        throw new IllegalArgumentException("Illegal load factor: " +
                                           loadFactor);
    this.loadFactor = loadFactor;
    this.threshold = tableSizeFor(initialCapacity);
}

示例

HashMap<Integer,String> hashMap = new HashMap<Integer, String>(-1,0.5f);

在这里插入图片描述

初始化容量操作

HashMap<Integer,String> hashMap = new HashMap<>(1<<32,0.5f);

this.threshold = tableSizeFor(initialCapacity);

/**
 * The next size value at which to resize (capacity * load factor).
 *
 * @serial
 */
// (The javadoc description is true upon serialization.
// Additionally, if the table array has not been allocated, this
// field holds the initial array capacity, or zero signifying
// DEFAULT_INITIAL_CAPACITY.)
int threshold;

表示获取最接近初始化值的2的次方值

static final int tableSizeFor(int cap) {
    int n = cap - 1;
    n |= n >>> 1;
    n |= n >>> 2;
    n |= n >>> 4;
    n |= n >>> 8;
    n |= n >>> 16;
    return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
}

首先,int n = cap -1是为了防止cap已经是2的幂时,执行完后面的几条无符号右移操作之后,返回的capacity是这个cap的2倍,因为cap已经是2的幂了,就已经满足条件了。 如果不懂可以往下看完几个无符号移位后再回来看。(建议自己在纸上画一下)

如果n这时为0了(经过了cap-1之后),则经过后面的几次无符号右移依然是0,最后返回的capacity是1(最后有个n+1的操作)。这里只讨论n不等于0的情况。
以16位为例,假设开始时 n 为 0000 1xxx xxxx xxxx (x代表不关心0还是1)

  • 第一次右移 n |= n >>> 1;

由于n不等于0,则n的二进制表示中总会有一bit为1,这时考虑最高位的1。通过无符号右移1位,则将最高位的1右移了1位,再做或操作,使得n的二进制表示中与最高位的1紧邻的右边一位也为1,如0000 11xx xxxx xxxx 。

  • 第二次右移 n |= n >>> 2;

注意,这个n已经经过了n |= n >>> 1; 操作。此时n为0000 11xx xxxx xxxx ,则n无符号右移两位,会将最高位两个连续的1右移两位,然后再与原来的n做或操作,这样n的二进制表示的高位中会有4个连续的1。如0000 1111 xxxx xxxx 。

  • 第三次右移 n |= n >>> 4;

这次把已经有的高位中的连续的4个1,右移4位,再做或操作,这样n的二进制表示的高位中会有8个连续的1。如0000 1111 1111 xxxx 。

测试结果

public static void main(String[] args) {
        int sizeFor = tableSizeFor(432);
        System.out.println(sizeFor);
        //>>>  :  无符号右移,忽略符号位,空位都以0补齐
        //00000000_00000000_00000000_00000111   7
        //00000000_00000000_00000000_00000011   3
        int a = 7 >>> 1;
        System.out.println(a);
        //00000000_00000000_00000000_00000111  7
        //00000000_00000000_00000000_00000011  3
        int b = 7;
        //按位或的结果
        //00000000_00000000_00000000_00000111
        b |= 3;
        System.out.println(b);
        b |= b>>>1;
        System.out.println(b);
}
// 此函数返回的结果表示获取最接近它的2的次方
static  int tableSizeFor(int cap) {
    int n = cap - 1;
    n |= n >>> 1;
    n |= n >>> 2;
    n |= n >>> 4;
    n |= n >>> 8;
    n |= n >>> 16;
    return (n < 0) ? 1 : (n >= 1<<30) ? 1<<30 : n + 1;
}

HashMap(Map<? extends K, ? extends V> m)

 /**
 * Constructs a new <tt>HashMap</tt> with the same mappings as the
 * specified <tt>Map</tt>.  The <tt>HashMap</tt> is created with
 * default load factor (0.75) and an initial capacity sufficient to
 * hold the mappings in the specified <tt>Map</tt>.
 *
 * @param   m the map whose mappings are to be placed in this map
 * @throws  NullPointerException if the specified map is null
 */
public HashMap(Map<? extends K, ? extends V> m) {
    this.loadFactor = DEFAULT_LOAD_FACTOR;
    putMapEntries(m, false);
}

调用了putMapEntries(m, false);方法

/**
 * Implements Map.putAll and Map constructor
 *
 * @param m the map
 * @param evict false when initially constructing this map, else
 * true (relayed to method afterNodeInsertion).
 */
final void putMapEntries(Map<? extends K, ? extends V> m, boolean evict) {
    // 获取现有Map的大小
    int s = m.size();
    // 当m 中有元素的时候,将Map中的元素放入到现在初始化的这个Map实例中
    if (s > 0) {
        //  判断table是否已经被初始化了,如果没有初始化先需要进行初始化一些变量
        //  例如装填因子初始化容量等参数
        if (table == null) { // pre-size
            //根据待插入的map的Size计算需要创建的Map的容量
            float ft = ((float)s / loadFactor) + 1.0F;
            //计算对应容量
            int t = ((ft < (float)MAXIMUM_CAPACITY) ?
                     (int)ft : MAXIMUM_CAPACITY);
            // 要把创建的的map的容量存在 threshold 中
            if (t > threshold)
                threshold = tableSizeFor(t);
        }
        //如果table初始化过了,因为还有其他函数的调用,所以有些Hashmap已经被初始化过了
        //判断需要插入的值是否大于现有的threshold,如果需要,则进行扩容操作resize();
        else if (s > threshold)
            resize();
        //然后就开始遍历需要插入的map ,将每一个KV都插入的本实例HashMap中
        for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
            K key = e.getKey();
            V value = e.getValue();
            putVal(hash(key), key, value, false, evict);
        }
    }
}

这里需要说明一下putVal,在HashMap出入值调用put方法的时候实际上也是调用这个方法。下一边分析一边来看看具体的参数都是什么意思

首先先来介绍一下HashMap中的几个私有属性

 /**
 * The table, initialized on first use, and resized as
 * necessary. When allocated, length is always a power of two.
 * (We also tolerate length zero in some operations to allow
 * bootstrapping mechanics that are currently not needed.)
 */
 // 用来存储实际的key,value的数组,只不过在HashMap中将其封装成了一个Node,下面会介绍
transient Node<K,V>[] table;
/**
 * Holds cached entrySet(). Note that AbstractMap fields are used
 * for keySet() and values().
 */
 //作为一个Key的缓存存在
transient Set<Map.Entry<K,V>> entrySet;
/**
 * The number of key-value mappings contained in this map.
 */
//Map中已有数据的大小
transient int size;
/**
 * The number of times this HashMap has been structurally modified
 * Structural modifications are those that change the number of mappings in
 * the HashMap or otherwise modify its internal structure (e.g.,
 * rehash).  This field is used to make iterators on Collection-views of
 * the HashMap fail-fast.  (See ConcurrentModificationException).
 */
 
transient int modCount;
/**
 * The next size value at which to resize (capacity * load factor).
 *
 * @serial
 */
// (The javadoc description is true upon serialization.
// Additionally, if the table array has not been allocated, this
// field holds the initial array capacity, or zero signifying
// DEFAULT_INITIAL_CAPACITY.)
// 因为 tableSizeFor(int) 返回值给了threshold
int threshold;
/**
 * The load factor for the hash table.
 *
 * @serial
 */
final float loadFactor;

在这里插入图片描述

这里首先关注两个点

Entry
Entry 是由Map提供的接口

在这里插入图片描述

Node
在这里插入图片描述

/**
 * Basic hash bin node, used for most entries.  (See below for
 * TreeNode subclass, and in LinkedHashMap for its Entry subclass.)
 */
static class Node<K,V> implements Map.Entry<K,V> {
    final int hash;
    final K key;
    V value;
    Node<K,V> next;
    Node(int hash, K key, V value, Node<K,V> next) {
        this.hash = hash;
        this.key = key;
        this.value = value;
        this.next = next;
    }
    public final K getKey()        { return key; }
    public final V getValue()      { return value; }
    public final String toString() { return key + "=" + value; }
    public final int hashCode() {
        return Objects.hashCode(key) ^ Objects.hashCode(value);
    }
    public final V setValue(V newValue) {
        V oldValue = value;
        value = newValue;
        return oldValue;
    }
    public final boolean equals(Object o) {
        if (o == this)
            return true;
        if (o instanceof Map.Entry) {
            Map.Entry<?,?> e = (Map.Entry<?,?>)o;
            if (Objects.equals(key, e.getKey()) &&
                Objects.equals(value, e.getValue()))
                return true;
        }
        return false;
    }
}

会看到在上面调用了putMapEntries 方法的时候调用了一个putVal而在传入参数的时候调用了一个hash()方法

static final int hash(Object key) {
    int h;
    return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}

这里有个异或运算

(h = key.hashCode()) ^ (h >>> 16);

这里我们知道Hash值是一个int类型的使用2个字节,也就是16位二进制表示

原 来 的 hashCode : 1111 1111 1111 1111 0100 1100 0000 1010
移位后的hashCode: 0000 0000 0000 0000 1111 1111 1111 1111
进行异或运算 结果:1111 1111 1111 1111 1011 0011 1111 0101

这样做的好处是,可以将hashCode高位和地位的值进行混合做异或运算,而且混合之后,地位的信息中加入了高位的信息,这样高位的信息就会被保留下来,掺杂的元素多了,那么生成的hash的随机性会增大。

这里在补充分析一下另外的一个方法扩容方法resize()

/**
 * Initializes or doubles table size.  If null, allocates in
 * accord with initial capacity target held in field threshold.
 * Otherwise, because we are using power-of-two expansion, the
 * elements from each bin must either stay at same index, or move
 * with a power of two offset in the new table.
 *
 * @return the table
 */
final Node<K,V>[] resize() {
    //保存当前table
    Node<K,V>[] oldTab = table;
    //保存当前table容量
    int oldCap = (oldTab == null) ? 0 : oldTab.length;
    //保存当前阈值
    int oldThr = threshold;
    //初始化新的Table的容量和阈值
    int newCap, newThr = 0;
    /**
    1、resize()函数在size > threshold 的时候被调用,
    oldCap 大于0 表示原来的table为非空,oldCap为原来表大小,
    oldThread 为原来容量oldCap x load_factor
    */
    if (oldCap > 0) {
        // 如果旧的table容量超过最大容量,更新阈值为最大整型值这样以后就不需要再操作了
        if (oldCap >= MAXIMUM_CAPACITY) {
            threshold = Integer.MAX_VALUE;
            return oldTab;
        }
        // 容量翻倍,使用左移操作效率高
        else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY &&
                 oldCap >= DEFAULT_INITIAL_CAPACITY)
            //阈值翻倍
            newThr = oldThr << 1; // double threshold
    }
    /**
    2、resize() 函数在table为空的时候调用,oldCap等于0且oldThr 大于0,代表用户创建了一个 HashMap ,但是使用的构造函数为HashMap(int initialCapacity, float loadFactor)或者HashMap(int initialCapacity)或 HashMap(Map<? extends K, ? extends V> m),导致 oldTab 为 null,oldCap 为0, oldThr 为用户指定的 HashMap的初始容量。
    */
    
    else if (oldThr > 0) // initial capacity was placed in threshold
        //当table没初始化时,threshold持有初始容量
        newCap = oldThr;
    /**
    3、resize() 函数在table为空被调用,oldCap小于等于0且oldThr等于0,用户调用了HasHMap()构造函数 HashMap,所有值均采用默认值,oldTab(Table)表为空,oldCap为0,oldThr等于0
    */
    else {               // zero initial threshold signifies using defaults
        newCap = DEFAULT_INITIAL_CAPACITY;
        newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY);
    }
    //新的阈值 为 0
    if (newThr == 0) {
        float ft = (float)newCap * loadFactor;
        newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ?
                  (int)ft : Integer.MAX_VALUE);
    }
    
    threshold = newThr;
    @SuppressWarnings({"rawtypes","unchecked"})
    //初始化table
    Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap];
    table = newTab;
    if (oldTab != null) {
        //把oldTab 中的节点 reHash 到 newTab中去
        for (int j = 0; j < oldCap; ++j) {
            Node<K,V> e;
            if ((e = oldTab[j]) != null) {
                oldTab[j] = null;
                // 如果是一个单节点,直接再newTab中进行定位
                if (e.next == null)
                    newTab[e.hash & (newCap - 1)] = e;
                // 如果节点是一个TreeNode 要进行红黑树的 reHash操作
                else if (e instanceof TreeNode)
                    ((TreeNode<K,V>)e).split(this, newTab, j, oldCap);
                // 如果是一个链表,进行链表的reHash操作
                else { // preserve order
                    Node<K,V> loHead = null, loTail = null;
                    Node<K,V> hiHead = null, hiTail = null;
                    Node<K,V> next;
                    //(e.hash & oldCap)按位与 是否为零
                    do {
                        next = e.next;
                        //如果为零
                        if ((e.hash & oldCap) == 0) {
                            if (loTail == null)
                                loHead = e;
                            else
                                loTail.next = e;
                            loTail = e;
                        }
                        //如果不为零
                        else {
                            if (hiTail == null)
                                hiHead = e;
                            else
                                hiTail.next = e;
                            hiTail = e;
                        }
                    } while ((e = next) != null);
                    // 
                    if (loTail != null) {
                        loTail.next = null;
                        newTab[j] = loHead;
                    }
                    if (hiTail != null) {
                        hiTail.next = null;
                        newTab[j + oldCap] = hiHead;
                    }
                }
            }
        }
    }
    return newTab;
}

链表扩容
在这里插入图片描述

什么时候进行扩容

通过HashMap源码可以看到是在put操作时,即向容器中添加元素时,判断当前容器中元素的个数是否达到阈值(当前数组长度乘以加载因子的值)的时候,就要自动扩容了。

扩容(resize):其实就是重新计算容量;而这个扩容是计算出所需容器的大小之后重新定义一个新的容器,将原来容器中的元素放入其中。


/**
 * Implements Map.put and related methods
 *
 * @param hash hash for key
 * @param key the key
 * @param value the value to put
 * @param onlyIfAbsent if true, don't change existing value
 * @param evict if false, the table is in creation mode.
 * @return previous value, or null if none
 */
final V putVal(int hash, K key, V value, boolean onlyIfAbsent,boolean evict) {
    Node<K,V>[] tab; Node<K,V> p; int n, i;
    //判断table是否为空或者长度为0,则进行resize();
    if ((tab = table) == null || (n = tab.length) == 0)
        n = (tab = resize()).length;
    // 确定需要插入表的位置
    if ((p = tab[i = (n - 1) & hash]) == null)
        tab[i] = newNode(hash, key, value, null);
    //当发生碰撞的时候,有两种情况,1、key值一样替换value值
    // 2、key值不一样
    // 2.1
    else {
        Node<K,V> e; K k;
        if (p.hash == hash &&
            ((k = p.key) == key || (key != null && key.equals(k))))
            e = p;
        else if (p instanceof TreeNode)
            e = ((TreeNode<K,V>)p).putTreeVal(this, tab, hash, key, value);
        else {
            for (int binCount = 0; ; ++binCount) {
                if ((e = p.next) == null) {
                    p.next = newNode(hash, key, value, null);
                    if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st
                        treeifyBin(tab, hash);
                    break;
                }
                if (e.hash == hash &&
                    ((k = e.key) == key || (key != null && key.equals(k))))
                    break;
                p = e;
            }
        }
        if (e != null) { // existing mapping for key
            V oldValue = e.value;
            if (!onlyIfAbsent || oldValue == null)
                e.value = value;
            afterNodeAccess(e);
            return oldValue;
        }
    }
    ++modCount;
    if (++size > threshold)
        resize();
    afterNodeInsertion(evict);
    return null;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1504282.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux随记(八)

一、crontab运行shell脚本&#xff0c;py脚本 &#xff08;注意事项&#xff09; 情景描述&#xff1a; 目前有个sh脚本他最初大致内容是。 cat t11.sh#!/bin/bash source /etc/profile /bin/python3 /tmp/1.py sh /tmp/1.sh echo -e "$(date %F)" >…

C语言指针、数组学习记录

指针 指针是什么 数据在内存中存放的方式 声明一个变量int i 3;&#xff0c;那么在内存中就会分配一个大小为4字节&#xff08;因为int类型占4字节&#xff09;的内存空间给变量i&#xff0c;这块内存空间存放的数据就是变量i的值。 换句话说就是&#xff0c;在内存中给变…

MySQL--优化(索引)

MySQL–优化&#xff08;索引篇&#xff09; 定位慢查询SQL执行计划索引 存储引擎索引底层数据结构聚簇和非聚簇索引索引创建原则索引失效场景 SQL优化经验 索引 索引&#xff08;index&#xff09;是帮助 MySQL 高效获取数据的数据结构&#xff08;有序&#xff09;。在数据…

【记录37】VueBaiduMap 踩坑一

截图 错误 Error in callback for watcher “position.lng”: “TypeError: Cannot read properties of undefined (reading ‘setPosition’)” 解释 回调观察程序“content”时出错&#xff1a;“TypeError:无法读取未定义的属性&#xff08;读取’setContent’&#xff09;”…

一文掌握:B端系统表单页的作用、组件、设计要点,另附大量案例

Hi&#xff0c;我是贝格前端工场&#xff0c;本篇分享表单页该如何设计&#xff0c;读罢此文让你对表单页有全方位的认识&#xff0c;欢迎点赞评论转发&#xff0c;有需求请私信我们。 一、表单页是什么 表单页是指在Web应用程序中用于收集和提交用户输入数据的页面。它通常由…

基于J2EE的在线考试系统设计与实现

目 录 摘 要 I Abstract II 引 言 1 1 相关技术 3 1.1 Java简介 3 1.2 JSP技术 3 1.3 MySQL数据库 4 1.4 B/S结构 4 1.5 本章小结 4 2 系统分析 5 2.1 需求分析 5 2.2 可行性分析 6 2.2.1 技术可行性 6 2.2.2 操作可行性 6 2.2.3 经济可行性 7 2.2.4 法律可行性 7 2.3 系统性能…

邓保康 App 技术支持

邓保康APP功能简介&#xff1a; 这是一款创新&#xff0c;稳定的商业购物型平台app&#xff0c;涵盖同城门店&#xff0c;便捷团购等业务需求。 如果使用过程中有任何疑问可以在帖子中提问&#xff0c;我们会第一时间进行答复和处理。 获得支持&#xff1a; 邮件&#xff1a…

kettle入门一 安装与基本使用

一、kettle概述 1、什么是kettle Kettle是一款开源的ETL工具&#xff0c;纯java编写&#xff0c;可以在Window、Linux、Unix上运行&#xff0c;绿色无需安装&#xff0c;数据抽取高效稳定。 2、Kettle工程存储方式 &#xff08;1&#xff09;以XML形式存储 &#xff08;2&…

Axure基础 各元件的作用及介绍

图像热区 增加按钮或者文本的点击区域&#xff0c;他是透明的&#xff0c;在预览时看不见。 动态面板 用来绘制一下带交互效果的元件&#xff0c;他是动态的&#xff0c;如轮播图&#xff0c;一个动态面板里可以有多个子面板&#xff0c;每一个子面板对应着不同的效果。 他…

像SpringBoot一样使用Flask - 4.拦截器

接上文《像SpringBoot一样使用Flask - 3.蓝图路由Blueprint》&#xff0c;我们已经整理了一个干净的"启动类"&#xff0c;现在要加入一些拦截器&#xff0c;为了方便统一管理。 一、常用的拦截器 # 拦截器 app.before_request def handle_before_request():"&qu…

文献阅读:DEA-Net:基于细节增强卷积和内容引导注意的单图像去雾

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 摘要Abstract文献阅读&#xff1a;DEA-Net&#xff1a;基于细节增强卷积和内容引导注意的单图像去雾1、研究背景2、方法提出3、相关知识3.1、DEConv3.3、多重卷积的…

Consul(安装,服务注册与发现,服务配置与动态刷新,配置持久化)

1.下载安装Consul 下载地址:Install | Consul | HashiCorp Developer 解压后只有一个.exe文件&#xff0c;运行后在该文件路径下输入consul --version 启动consul开发模式:consul agent -dev 访问localhost:8500进去consul主页 2.服务注册与发现 官方配置手册:Quick Start :…

进程控制(二) 进程等待与进程替换

目录 一、进程等待 理解进程等待 演示进程等待 获取进程的status 进程等待接口讲解 wait用法​ waitpid用法 等待多进程 基于非阻塞调用的轮询式检测 二、进程程序替换 excel接口 程序替换演示 单进程程序替换 多进程程序替换 程序替换原理 单进程程序替换 多…

Web Worker:JavaScript的后台任务解决方案

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

阿里云服务器ECS u1实例2核4G5M带宽优惠价199元/年性能测评

阿里云服务器ECS u1实例&#xff0c;2核4G&#xff0c;5M固定带宽&#xff0c;80G ESSD Entry盘优惠价格199元一年&#xff0c;性能很不错&#xff0c;CPU采用Intel Xeon Platinum可扩展处理器&#xff0c;购买限制条件为企业客户专享&#xff0c;实名认证信息是企业用户即可&a…

每日OJ题_牛客HJ60 查找组成一个偶数最接近的两个素数

目录 牛客HJ60 查找组成一个偶数最接近的两个素数 解析代码 牛客HJ60 查找组成一个偶数最接近的两个素数 查找组成一个偶数最接近的两个素数_牛客题霸_牛客网 解析代码 #include <cmath> #include <iostream> using namespace std; bool isPrime(int n) {for (…

STM32H750片外QSPI启动配置简要

STM32H750片外QSPI启动配置简要 &#x1f4cd;参考信息源&#xff1a;《STM32H750片外Flash启动(W25Q64JVSIQ)》&#x1f516;本例程基于Keil MDk开发平台。&#x1f341;配置框架&#xff1a; ✨为什么使用要使用QSPI启动方式 不管对于STM32H7系列单片机&#xff0c;还是其他…

BC134 蛇形矩阵

一&#xff1a;题目 二&#xff1a;思路分析 2.1 蛇形矩阵含义 首先&#xff0c;这道题我们要根据这个示例&#xff0c;找到蛇形矩阵是怎么移动的 这是&#xff0c;我们可以标记一下每次移动到方向 我们根据上图可以看出&#xff0c;蛇形矩阵一共有两种方向&#xff0c;橙色…

解决ChatGPT发送消息没有反应

ChatGPT发消息没反应 今天照常使用ChatGPT来帮忙码代码&#xff0c;结果发现发出去的消息完全没有反应&#xff0c;即不给我处理&#xff0c;也没有抱任何的错误&#xff0c;按浏览器刷新&#xff0c;看起来很正常&#xff0c;可以查看历史对话&#xff0c;但是再次尝试还是一…

一分钟了解遥感中卫星、传感器、波段及数据之间的关系

感是利用卫星、飞机或其他载具上的传感器对地球表面进行观测和测量的科学技术。以下是一些常见的遥感相关术语&#xff1a; 卫星&#xff08;Satellite&#xff09;&#xff1a;在遥感中&#xff0c;卫星是指绕地球轨道运行的人造卫星&#xff0c;其主要任务是携带各种传感器从…