小编Ale*_*tto的帖子

对HashTable性能问题感到好奇

我读到Haskell中的哈希表存在性能问题(2006 年的Haskell-Cafe和2009年的Flying Frog Consultancy的博客),因为我喜欢Haskell,所以我很担心.

那是一年前,现在的状况是什么(2010年6月)?GHC中是否修复了"哈希表问题"?

haskell hashtable ghc

50
推荐指数
3
解决办法
1万
查看次数

std :: array是否可以移动?

std :: array是否可以移动?

Bjarne Native 2012演示幻灯片(幻灯片41)中,它std::array列为唯一不可移动的容器之一.

快速浏览gcc 4.8库源代码似乎证实std::array不可移动:

的std ::向量:

/* @brief  %Vector move constructor.
   ...       */
  vector(vector&& __x) noexcept
  : _Base(std::move(__x)) { }
Run Code Online (Sandbox Code Playgroud)

在std :: array中,接收rvalue引用参数的唯一方法是随机元素访问,这避免了通过复制返回:

get(array<_Tp, _Nm>&& __arr) noexcept
    { /*...*/ return std::move(get<_Int>(__arr)); }
Run Code Online (Sandbox Code Playgroud)

是否std::array创建了默认的move-constructor和move-assignment ,或者是std::array不可移动的?如果它是不可移动的,为什么std::array不能移动std::vector呢?

c++ arrays move-semantics c++11

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

什么是scanf格式输入的cin analougus?

通过scanf,通常可以直接获取格式化输入:

1)具有大于0且小于1的实数的行.在'x'上结束,例如:0.32432523x

scanf("0.%[0-9]x", &number);
Run Code Online (Sandbox Code Playgroud)

2)line代表格式的加法:30 + 28 =五十八

scanf(":%d+%d=%99s", &number1, &number2, &total);
Run Code Online (Sandbox Code Playgroud)

什么是cin解决方案,只使用标准库?

c++ input std

15
推荐指数
2
解决办法
7152
查看次数

如何将SFML游戏服务器部署到Linux服务器?

我写了一个迷你客户端 - 服务器游戏,在我的计算机上运行正常(运行linux),因为我在客户端和服务器上安装了SFML(和GCC 4.8).现在我想将服务器应用程序部署到另一个没有SFML的Linux上.

首先,我尝试动态链接使用的SFML库(网络和系统):

g++ server.cpp -o ServerLinux -std=c++11 -Os -lsfml-network -lsfml-system
Run Code Online (Sandbox Code Playgroud)

但是,当我运行Server应用程序时,它说它无法找到sfml-network.so.2和sfml-system.so.2,即使这两个文件位于二进制文件的同一文件夹中.

然后我静态链接两个库:

g++ -DSFML_STATIC server.cpp -o ServerLinux -std=c++11 -Os -lsfml-network-s -lsfml-system-s
Run Code Online (Sandbox Code Playgroud)

然后当我运行它说它找不到GLIBC_2.15和GLIBC_2.17

最后在我的最后一次尝试中我将libstc ++和libgcc静态链接:

g++ -DSFML_STATIC server.cpp -o ServerLinux -std=c++11 -Os -lsfml-network-s -lsfml-system-s -static-libstdc++ -static-libgcc
Run Code Online (Sandbox Code Playgroud)

但我仍然得到相同的错误(找不到GLIBC_2.15和GLIBC_2.17).

阅读类似的问题似乎永远不应该静态链接glibc.但我不知道如何继续,如何将我的迷你游戏服务器部署到没有SFML的Linux机器上?

c++ linux gcc sfml

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

如何实现对二叉搜索树右边缘值的可变引用的迭代器?

我在Rust中实现了一个简单的二进制搜索树(遵循CIS 198,它很棒),并且为了学习我正在做的迭代器只是通过正确的边缘.

我无法实现一个提供可变引用的迭代器.我尝试了很多方法,但Rust编译器都没有接受.我需要帮助的代码是下面的代码(虽然我在这里给出了完整代码的要点):

#[derive(Debug)]
pub struct Tree<T>(Option<Box<Node<T>>>);

#[derive(Debug)]
pub struct Node<T> {
    elem: T,
    left: Tree<T>,
    right: Tree<T>,
}

// MUTABLE BORROW STRUCT
pub struct IterMut<'a, T: 'a> {
    next: &'a mut Tree<T>,
}

// MUTABLE BORROW NEXT (I'M STUCK HERE, NOTHING WORKS)
impl<'a, T> Iterator for IterMut<'a, T> {
    type Item = &'a mut T;
    fn next(&mut self) -> Option<Self::Item> {
        // 1 try: cannot infer lifetime
        self.next.0.as_mut().map(|node| {
            self.next = &mut node.right;
            &mut node.elem
        })

        // …
Run Code Online (Sandbox Code Playgroud)

rust

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

这个线路交叉如何工作?

我正在建造一个小组赛的Asteroids游戏.为了完成它我需要一个线交叉算法/代码.我找到了一个有效的,但我不理解它背后的数学.这是如何运作的?

point* inter( point p1, point p2, point p3, point p4)
{
point* r;

//p1-p2 is the first edge. 
//p3-p4 is the second edge.
r = new point;
float x1 = p1.x, x2 = p2.x, x3 = p3.x, x4 = p4.x;
float y1 = p1.y, y2 = p2.y, y3 = p3.y, y4 = p4.y;

//I do not understand what this d represents.
float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); …
Run Code Online (Sandbox Code Playgroud)

c++ math

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

这段代码(容器遍历的宏)是否有效?如果有,为什么?

在关于TopCoder的Dmitry Korolev教程之后,我遇到了这个泛型容器遍历宏:

#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
Run Code Online (Sandbox Code Playgroud)

它让我困惑,因为它似乎缺少一个括号.在解释中,他说typeof(...)被表达式(...)的类型所取代,这让我对这个遍历宏更加困惑(因为我的直觉看到typeof(x; y; z)和因为x; y; z不是表达式,即使它工作了typeof(...)也会"吃掉"(...)).

它有用吗?为什么?

c++ macros containers

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

如何迭代字典/文本框表?

我有一个文本框表,其中键是位置的名称(topRight,topLeft ...).

一次创建和配置一个工作正常:

kanaAt = {}
function startKanas ()
    kanaAt.topLeft = MOAITextBox.new()  
    kanaAt.topLeft:setFont(font)
    ...
    kanaAt.topLeft:setString("?")
    layer:insertProp (kanaAt.topLeft)

    kanaAt.topRight = MOAITextBox.new()
    kanaAt.topRight:setFont(font)
    ...
    kanaAt.topRight:setString("?")
    layer:insertProp (kanaAt.topRight)
end
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试迭代它时,不是这样:

kanaAt = {}
function startKanas ()
    kanaAt.topLeft = MOAITextBox.new()
    kanaAt.topRight = MOAITextBox.new() 
    kanaAt.bottomLeft = MOAITextBox.new()
    kanaAt.bottomRight = MOAITextBox.new()          

    for name, text in ipairs(kanaAt) do
        text:setFont(font)
        text:setTextSize(90,60)
        text:setYFlip(true)
        text:setRect(-50,-50,50,50)
        layer:insertProp (text)
    end

    kanaAt.topLeft:setString("?")
    kanaAt.topLeft:setLoc(-325, 225)
    kanaAt.topRight:setString("?")
    kanaAt.topRight:setLoc(325, 225)
    kanaAt.bottomLeft:setString("?")
    kanaAt.bottomLeft:setLoc(-325, -225)
    kanaAt.bottomRight:setString("?")
    kanaAt.bottomRight:setLoc(325, -225)

end
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

lua moai

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

TypeScript:为什么让print = console.log.bind(console)只在前面有导入的情况下才有效?

我有点困惑:

let print = console.log.bind(console)
Run Code Online (Sandbox Code Playgroud)

不起作用(给出"不能重新声明块范围变量'print'"),但这完美地起作用:

import { readFileSync } from 'fs' //or even import { } from 'anything'
const print = console.log.bind(console)
Run Code Online (Sandbox Code Playgroud)

更令人费解的是,使用变量的另一个名称(如"printIt")可行.

发生了什么?

typescript

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

标签 统计

c++ ×5

arrays ×1

c++11 ×1

containers ×1

gcc ×1

ghc ×1

hashtable ×1

haskell ×1

input ×1

linux ×1

lua ×1

macros ×1

math ×1

moai ×1

move-semantics ×1

rust ×1

sfml ×1

std ×1

typescript ×1