涉及非常大的数组索引存储非常大值的问题的替代方案 [英] Alternatives for problems involving very large array indexing storing very large values

查看:107
本文介绍了涉及非常大的数组索引存储非常大值的问题的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请提出一些解决方法,解决蛮力解决方案使用具有非常大的索引的数组并存储非常大的值(非常大的意味着超出 INT 范围)的问题。我正在使用 Java 来解决这个问题。



示例问题:
放大大小的鹅卵石在一大堆桶中,然后计算每个桶中的平均鹅卵石。



一种方法是声明一个大阵列,并根据指定的索引继续放置鹅卵石用户然后计算平均值。但是这样我们将使用这样的数组的大空间。

解决方案

如果数组是稀疏的,一个选项可能是



如果所有数据仍然适用于内存,索引只是超出了 int 的范围,你可以考虑数组数组。主阵列可以包含大小的数组,我们说1000000000.这个数组中的第0个索引将包含0-999999999,第1个索引,1000000000-1999999999等。



另一个选择是使用文件 RandomAccessFile 可能有助于手动执行,或者可能有一些库为您提供阵列接口,并在后台处理文件I / O。


Please suggest some alternatives for resolving problems in which brute force solution is using Arrays with very large index and storing very large values(Very large means beyond the range of INT). I am using Java to solve this problem.

Sample problem: Putting large no of pebbles in a very large group of buckets, and then calculating average pebbles in each bucket.

One way is to declare a big array and keep placing pebbles according to the indexes specified by user and then calculating average. But this way we'll be using a large space for such array.

解决方案

If the array is sparse, one option could be a Map of index to value.

If all the data can still fit into memory, the index is just beyond the range of int, you could consider an array of arrays. The primary array can contain arrays of size let's say 1000000000. The 0th index in this array would contain values 0-999999999, the 1st index, 1000000000-1999999999, etc.

Another alternative is using files. A RandomAccessFile might help to do this manually, or there may be some libraries that give you an array interface and takes care of the file I/O behind the scenes.

这篇关于涉及非常大的数组索引存储非常大值的问题的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆