Questions tagged [space-efficiency]

67 questions
1
vote
1 answer

How can I store an image file in the utf-8 HTML source with the fewest bytes as possible?

One can think at first at the base64 encoding, and base64 data-uri. But is it the most space efficient solution? My use case is to store tiny captcha images aside clickable links, which are gif or png files, 500-2000 bytes in size, somehow…
Konstantin
  • 2,983
  • 3
  • 33
  • 55
1
vote
1 answer

Does assigning same value to datatype decrease efficiency?

For example, I have an infinite while loop which keeps assigning true to our testBool: boolean testBool; while(true) { testBool = true; ...more logic... } Are we wasting computation on reassigning the same value to our datatype, or are…
1
vote
2 answers

How to permanently delete recent git commits from actual database

Example So let's say I have a local git repo with 10 commits, having SHA digests 0-9 so my git log looks like this 9 (HEAD -> master) 8 7 6 5 4 3 2 1 0 <- initial commit and I decide that commits 5-9 are garbage and I would like to permanently…
RBF06
  • 2,013
  • 2
  • 21
  • 20
1
vote
1 answer

Fastest way to sum the elements of a matrix

I have some problems with the efficiency of my code. Basically my code works like this: a = zeros(1,50000); for n = 1:50000 a(n) = 10.*n - 5; end sum(a); What is the fastest way to solve the sum of all the elements of this matrix?
1
vote
1 answer

Efficient storage of large matrix on HDD

I have many large 1GB+ matrices of doubles (floats), many of them 0.0, that need to be stored efficiently. I indend on keeping the double type since some of the elements do require to be a double (but I can consider changing this if it could lead to…
user2763361
  • 3,789
  • 11
  • 45
  • 81
1
vote
4 answers

Referencing an object more than once in a line

So I'm writing my version of Tetris. Here's what I'd like to do: screen[0][1].setColor(Color.RED); screen[0][1].setStatus(1); Is there a way to do this in only one line?
1
vote
2 answers

How to combine exceptions to get rid of repeat code?

How can I minimize the repeated exception throwing code in the code: public R get(int index) throws IndexException { if (!((0 <= index) && (index < this.info.length))) { throw new IndexException(); } return this.info[index]; } public void…
1
vote
2 answers

How to read each lines of the input and output them in sorted order?

Duplicate lines should be printed the same number of times they occur in the input. Special care needs to be taken so that a file with a lot of duplicate lines does not use more memory than what is required for the number of unique lines. I've tried…
Manuel
  • 976
  • 3
  • 9
  • 21
1
vote
2 answers

Most space efficient way to store large integer from php to mysql?

I'm working with integers greater up to 128 bits long. They're used to store a large set of flags and I don't need to do any weird math with them, so I can treat it like a string in php to get around the PHP_INT_MAX limit. I think want to store…
Matthew
  • 6,351
  • 8
  • 40
  • 53
1
vote
4 answers

What is Java's lightest weight non-concurrent implementation of Iterable?

I need a class that implements Iterable, and does not need to be safe for concurrent usage. Of the various options, such as LinkedList, HashSet, ArrayList etc, which is the lightest-weight? To clarify the use-case, I need to be able to add a number…
sanity
  • 35,347
  • 40
  • 135
  • 226
1
vote
1 answer

using BIT as INT for storage volume efficiency

If I'm understanding correctly, BIT is extremely disk efficient. For my case, I know I will always only have three values which I'd like to treat like INTs: 1, 2, & 3. Am I correct that b'00' is 3 and different from b'0', 1? If I try to use INT…
user1382306
1
vote
3 answers

Space efficiency of algorithms

It seems like none of the algorithm textbooks mentions about space efficiency as much, so I don't really understand when I encounter questions asking for an algorithm that requires only constant memory. What would be an example of a few examples of…
John
1
vote
0 answers

How to most efficiently fill a printed page with 1 main image and scaled padding images?

I am printing panoramas with aspect ratios between 1.7:1 and 8:1. A common case is an image which scales to 18" x 8" leaving 4 inches on a standard 12x18 inch page. Paper only comes in so many sizes, but my images can be almost any size. I hate to…
user1556337
  • 151
  • 1
  • 4
1
vote
1 answer

character frequency calculation in string

I am looking for the most efficient (time and space) algorithm for character frequency calculation for a given string. The simplest algorithm that comes to mind is to have a flag-array (size = number of different characters) you want to search and…
Deepanjan Mazumdar
  • 1,447
  • 3
  • 13
  • 20
1
vote
3 answers

Memory and speed efficient search on Strings

I have a bunch of Strings I'd like a fast lookup for. Each String is 22 chars long and is looked up by the first 12 only (the "key" so to say), the full set of Strings is recreated periodically. They are loaded from a file and refreshed when the…
Arne
  • 1,884
  • 1
  • 15
  • 19