改变一个java类

发布于 2024-10-19 23:45:00 字数 494 浏览 2 评论 0 原文

我发现 BigInteger 类的实现可能更快。任何人都可以告诉我如何用这个更改在 java.math 中找到的原始 BigInteger 类。 提前致谢。

实际上,这不是我的实现,它出现在 http://www.mail-archive.com/ ,。 每一个改进都是他们的工作而不是我的,我只是尝试使用它。

I have found a potentially faster implementation of the BigInteger class. Anyone can tell me how can I change the original BigInteger class found in java.math with this one please.
Thanks in advance.

Actually, it is not my implementation, it is presented in http://www.mail-archive.com/[email protected]/msg01746.html,.
Every improvement is their work not mine, I am just trying to use it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

治碍 2024-10-26 23:45:00

不。只需包含可能更快的实现的 jar 文件(或类文件或源),然后实例化它即可。

Don't. Simply include the jar file (or class file, or source) of the potentially faster implementation, and instantiate it instead.

浪漫人生路 2024-10-26 23:45:00

我认为您是在问如何使用“java.math.BigInteger”而不是 JVM 版本。

我认为您不想这样做,因为这需要您更新使用您的应用程序的所有 JDK/JRE。更好的解决方案是使用“YourBigInteger”而不是应用程序中的 BigInteger。

您还可能会问如何让大众看到它并将其包含在 JDK/JRE 中。在这种情况下,我会说从 OpenJDK 开始。

I think you are asking how to use your "java.math.BigInteger" instead of the JVMs version.

I don't think you want to do this because it would require you to update all the JDK/JRE that use your application. A better solution is to your "YourBigInteger" instead of the BigInteger in your application.

You could also be asking how to get it looked at by the masses to be included in a JDK/JRE. In that case, I would say start with OpenJDK.

少年亿悲伤 2024-10-26 23:45:00

几乎没有理由要与您的 Java 中的 BigInteger 进行交换,除非您完全确定它不仅在所有相关情况下更快,而且对于所有依赖于原始 BigInteger 的程序也可以安全使用,并且在内部不会与 Java 发生冲突(甚至开发人员也可能没有注意到)。

如果上述所有内容均为真,那么您确实将您的类提交给 Oracle,因为我确信他们正在不断寻找更高效的实现,并且您可以通过在 Java 7 或 8 中发布更快的 BigInteger 类来真正帮助我们所有人, 也许。

但是既然你说你只是“可能”找到了一个更快的实现,那么你真正想要的是一个子类:

public class FastBigInteger extends java.math.BigInteger
{

并重写你认为可以加速的所有方法

    public BigInteger divide(BigInteger val)
    {
        //your faster implementation goes here
    }
}

,然后你可以开始针对 java 的类测试这个类,计时运行多个测试用例中每个测试用例的时间,并将结果呈现给 Oracle。

There's almost no reason why you would want to exchange BigInteger in Java with yours, unless you're absolutely sure that it's not only faster in ALL relevant cases, but is also safe to use for all programs that would have depended on the original BigInteger, and doesn't conflict with Java internally (at a level even developers may not notice).

If all of the above are true, then you really submit your class to Oracle, because I'm sure they're looking for more efficient implementations constantly and you could really help us all out by releasing your faster BigInteger class in Java 7 or 8, perhaps.

But since you say you've only "potentially" found a faster implementation, what you really want is a subclass:

public class FastBigInteger extends java.math.BigInteger
{

and override all the methods you think can be sped up

    public BigInteger divide(BigInteger val)
    {
        //your faster implementation goes here
    }
}

and then you can start testing this class against java's class, timing the running time of each for many test cases, and presenting the findings to Oracle.

挖个坑埋了你 2024-10-26 23:45:00

Java 从 rt.jar 获取所有内置类。您可以将 BigInteger 类替换为该 JAR 中的另一个实现。

当然,我不会推荐它。几乎在所有情况下,扩展 BigInteger 都是一个更好的主意。但这是可以做到的。

Java gets all of its built-in classes from rt.jar. You could replace the BigInteger class with another implementation within that JAR.

Of course, I wouldn't recommend it. Extending BigInteger would in almost all situations be a much better idea. But it can be done.

各自安好 2024-10-26 23:45:00

您应该能够通过 Java“认可”机制覆盖 JRE 中提供的类:

http://download.oracle.com/javase/6/docs/technotes/guides/standards/

但是,我完全同意上述内容 - 如果可能的话,您应该简单地使用您的类而不是替换BigInteger:此方法不需要更改 JRE,并且不存在破坏依赖于 BigInteger 的其他包的风险。

但是,如果您有一个使用 BigInteger 的第 3 方包,并且您出于某种原因想要切换其下的实现(仔细考虑一下),那么认可的机制可能就是您所需要的。

You should be able to override classes shipped in the JRE through the Java "endorsed" mechanism:

http://download.oracle.com/javase/6/docs/technotes/guides/standards/

However, I completely agree with the above - if possible you should be simply using your class instead of replacing BigInteger: this method doesn't require changing the JRE, and there's no risk of breaking some other package that depends on BigInteger.

However, if you have a 3rd-party package that uses BigInteger, and you want to switch the implementation under it for some reason (think long about this), the endorsed mechanism may be what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文