小编Nab*_*bla的帖子

LinkedHashMap.removeEldestEntry有什么用?

我知道这个问题的答案很容易在互联网上找到.如果我选择不这样做,我需要知道会发生什么removeEldestEntry.以下是我的代码:

package collection;

import java.util.*;

public class MyLinkedHashMap {

   private static final int MAX_ENTRIES = 2;

   public static void main(String[] args) {
      LinkedHashMap lhm = new LinkedHashMap(MAX_ENTRIES, 0.75F, false) {

         protected boolean removeEldestEntry(Map.Entry eldest) {
            return false;
         }
      };
      lhm.put(0, "H");
      lhm.put(1, "E");
      lhm.put(2, "L");
      lhm.put(3, "L");
      lhm.put(4, "O");

      System.out.println("" + lhm);

   }
}
Run Code Online (Sandbox Code Playgroud)

即使我不允许removeEldestEntry我的代码工作正常.那么,内部发生了什么?

java collections

22
推荐指数
4
解决办法
2万
查看次数

C和C++标准的数学精度要求

难道C和C++标准要求在数学运算math.h上的浮动点(即sqrt,exp,log,sin,...)返回数值最佳的解决方案?

对于给定的(精确且有效的)输入,通常显然不是这些函数的精确浮点输出.但输出是否必须是最接近数学上精确值的可表示值?

如果没有,是否有任何关于精度的要求(可能是平台特定的/在其他标准中?),以便我能够在我的代码中对计算错误进行最坏情况估计?现代实施的数值误差的典型限制是什么?

c c++ floating-point math.h

12
推荐指数
1
解决办法
1048
查看次数

从networkx中的文件读取具有pos属性的节点

我是Networkx的新手.我有一个包含以下格式的节点位置的文件

0 : 23.23 12.23

其中0是一个节点,23.2312.23分别是X和Y坐标.有谁知道如何读取具有pos属性的节点,使用类似read_edgelist(...)或类似的功能?

谢谢

python networkx

2
推荐指数
1
解决办法
1930
查看次数

在添加和计算时,sizeof如何适用于不同的数据类型?

#include <stdio.h>

int main()
{
    short int i = 20;
    char c = 97;
    printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这段代码的输出是

2, 1, 4
Run Code Online (Sandbox Code Playgroud)

根据我应该是

2, 1, 2
Run Code Online (Sandbox Code Playgroud)

因为char + short intshort int和大小的short int2.

c sizeof

2
推荐指数
1
解决办法
141
查看次数

使用std :: deque <std :: string>时出错

当我在我的班级中使用std :: deque作为私人成员时,我会遇到很多错误,例如

/usr/include/c++/v1/deque:907:49: error: implicit instantiation of undefined template 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >' static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16;

/usr/include/c++/v1/deque:1181:30: error: '__alloc_traits' is a protected member of 'std::__1::__deque_base<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >' typedef typename __base::__alloc_traits __alloc_traits;

等等.

它在我使用矢量时有效,但我想要一个pop_front功能.

有任何想法吗?

编辑:
代码:

#include <deque>
class Example {
    public:
        Example() {}
        ~Example() {}
    private:
        std::deque<std::string> m_deque;
};
Run Code Online (Sandbox Code Playgroud)

c++ string deque

1
推荐指数
1
解决办法
992
查看次数

使用带有整数的列对文本文件的行进行排序-

我需要使用其中一列(第一列)的整数值对文本文件的行进行排序。文件(coord.xyz)如下所示

9  1  -1.379785  0.195902  -1.197553
5  4  -0.303549  0.242253  -0.810244
2  2  -0.582923  1.208243  1.566588
3  3  -0.494556  0.028594  0.763130
4  1  -0.749005  -1.209878  1.358057
1  1  -0.883509  1.111866  2.882335
6  1  -1.005786  -1.278486  2.719391
7  5  -1.128898  -0.088124  3.508042
10  1  -0.253070  -0.289294  5.424662
8  1  -1.243879  -0.217228  5.247915
Run Code Online (Sandbox Code Playgroud)

我用了代码

import numpy as np

with open("coord.xyz") as inf:
    data = []
    for line in inf:
        line = line.split()
        if len(line)==5:
            data.append(line)
f_h = file('sorted.dat','a')
m = …
Run Code Online (Sandbox Code Playgroud)

python sorting numpy

0
推荐指数
1
解决办法
1914
查看次数

错误:在`>`标记之前的预期主表达式

我有这个代码有错误,无法找到它.

    if (Lista.at(i).getStartHour() <= temp->getStartHour() &&
 Lista.at(i).getEndHour() => temp->getEndHour() &&
         Lista.at(i).getStartMinute() < temp->getStartMinute() && 
    Lista.at(i).getEndMinute() > temp->getEndMinute())
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

error: expected primary-expression before '>' token at that line.
Run Code Online (Sandbox Code Playgroud)

我看不出我做错了什么.

Lista是一个vector对象,同一个对象temp.所有功能都返回int.我正试图检查那些时间是否重叠.

c++ compiler-errors token

0
推荐指数
1
解决办法
5931
查看次数