问题列表 - 第31274页

防止长时间运行平均溢出?

假设我想计算数据集的平均值,例如

class Averager {
   float total;
   size_t count;
   float addData (float value) {
       this->total += value;
       return this->total / ++this->count;
   }
}
Run Code Online (Sandbox Code Playgroud)

早晚totalcount值会溢出,所以我让不记得总价值:

class Averager {
   float currentAverage;
   size_t count;
   float addData (float value) {
       this->currentAverage = (this->currentAverage*count + value) / ++count;
       return this->currentAverage;
   }
}
Run Code Online (Sandbox Code Playgroud)

看来他们会溢出较长,但之间的乘法averagecount导致溢出的问题,所以接下来的解决办法是:

class Averager {
   float currentAverage;
   size_t count;
   float addData (float value) {
       this->currentAverage += (value - this->currentAverage) / ++count;
       return this->currentAverage;
   }
}
Run Code Online (Sandbox Code Playgroud)

似乎更好,接下来的问题是如何防止count …

c++ math average numeric overflow

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

比较javascript中的时间

我需要创建一个根据时间过滤数据的函数.

我有一张相关行的出发时间的航班表,我需要的是,我会把时间过滤到我的表格,以便在选定的时间之前和之后隐藏航班.换句话说,在所选时间间隔之间的飞行将是可见的.

我从表格和输入中获取时间信息没有问题,但我现在不知道如何比较它们.我用jquery.

javascript time

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

流畅的NHibernate JoinedSubClass已经过时了

我不知道什么.我坐在这里有一个解决方案我有1个超类,有2个子类,我现在使用JoinedSubClass映射它,但我得知这个方法已经过时,并说我应该使用ClassMap和SubClassMap,但如果我这样做AutoMapping不起作用,我不希望这样.这有什么解决方法吗?

这是层次结构:

public class Tag : Entity
{

public virtual string Name {get;set;}
public virtual User User {get;set;}

}

public class RespondentTag : Tag
{
    public virtual IList<Respondent> Respondents {get;set;}
}


public class ArchiveTag : Tag
{
    public virtual IList<Survey> Surveys {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

正如您可能想到的那样,我希望这是一个每个层次结构的表 - 映射与子类的列表是多对多.就像表'Tag',然后是Tag_Respondent和Tag_Archive(用于多对多关系).

这是我目前正在使用的映射:

public class TagMap : IAutoMappingOverride<Tag>
{
  public void Override(AutoMapping<Tag> mapping)
  { 
     //This is obsolete
     mapping.JoinedSubClass("RespondentTagId", RespondentTagMap.AsJoinedSubClass());
     mapping.JoinedSubClass("ArchiveTagId", ArchiveTagMap.AsJoinedSubClass());

  }
}

public class RespondentTagMap
{
    public static Action<JoinedSubClassPart<RespondentTag>> AsJoinedSubClass()
    {
     return part =>

        part.HasManyToMany(x …
Run Code Online (Sandbox Code Playgroud)

.net nhibernate fluent-nhibernate automapping joined-subclass

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

iphone:通过代码在Target的设置中获取User Defined变量?

我的项目有多个目标.每个目标都有自己的Class文件来设置东西.我想将该Class名称存储在目标设置(Info.plist或Target的Building设置)中.这样我就可以根据这个设置定义我需要在每个目标中使用哪个类.

根据这个问题,我User Defined在每个Target的建筑设置中放置了"特定于目标的变量".

但不知道如何在我的代码中取回它?

iphone xcode target xcconfig

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

如果我不使用else条件,有什么区别

这两个例子有什么区别:

if(firstchek)
{
    if(second)
    {
     return here();
    }
    else
    {
    return here();
    }
}
Run Code Online (Sandbox Code Playgroud)

还有这个:

if(firstcheck)
{
    if(second)
    {
     return here();
    }
      return here();
    // else code without else
}
// code without else
// else code is here 
     return here();
Run Code Online (Sandbox Code Playgroud)

c#

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

用于查找尚未使用的最简单的整数组合的算法

我正在寻找一种算法,用于找到从0到5的整数的最简单组合(即由最少数量的整数组成的整数),这些整数尚未使用(所使用的组合在列表中).

订单确实很重要,组合应该在列表中返回.

例如,使用过的数字的列表可能如下所示:

{{0},{1},{2},{3},{4},{0,0},{0,1},{0,2},...,{2,1},{ 2,2},...,{1,5,4},...}

在这种情况下,算法应该返回一个{5}的列表,因为{5}是由最少的整数组成的组合.

如果列表如下所示:

{{0},{1},{2},{3},{4},{5},{0,0},{0,1},{0,2},{0,3},{ 0,5},...}

算法应该返回一个0和4({0,4})的列表.

由于它将在Java中使用,因此Java答案是可取的,但伪代码或其他编程语言也是可用的.

先感谢您!

java algorithm combinations combinatorics

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

在UserControl中禁用Alt + F4

我有一些用户控制,我想为最终用户禁用Alt+ F4oportunity.当我的用户控件显示时,有机会用Alt+ 关闭它F4,然后程序转到方法中的基类:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
    //Content = null; // Remove child from logical parent - for reusing purposes
    this.RemoveLogicalChild(Content); //this works faster
    base.OnClosing(e);
    { GC.Collect(); };
}
Run Code Online (Sandbox Code Playgroud)

我必须在这里或其他地方做什么,禁止我的用户控制关闭Alt+ F4

c# wpf keyboard-shortcuts

5
推荐指数
3
解决办法
8102
查看次数

当存储块请求不是2的幂时会发生什么?

假设我们对大小为n的内存块执行malloc请求,其中k ^ 0为2 ^ k!= n.Malloc为请求的内存块返回空间,但是如何从页面处理stillig缓冲区.我读过Pages通常是内存块,它们是2的幂.

Wiki声明如下:

 Like any method of memory allocation, the heap will become fragmented; that is,
 there will be sections of used and unused memory in the allocated 
 space on the heap. A good allocator will attempt to find an unused area
 of already allocated memory to use before resorting to expanding the heap.
Run Code Online (Sandbox Code Playgroud)

所以我的问题是如何追踪?

编辑:使用malloc时如何跟踪未使用的内存?

c linux malloc

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

析构函数或解构函数?

在我的日常生活中,在阅读书籍的过程中,我看到过析构函数和解构函数.

但是这个方法的正确名称是什么?

oop terminology

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

MEF:DirectoryPartCatalog

我正在尝试编写一个简单的MEF演示来了解它.我正在学习教程,但它似乎已经过时了.可下载的示例有效,但它使用的是比Framwework 4附带的当前版本(4.0)更旧的版本(2008.9.4.0).

特别是,它使用我在最新的库中找不到的DirectoryPartCatalog.任何人都可以提供一个示例,说明如何从当前版本的MEF发现目录中的可插入程序集?

谢谢

.net c# mef

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