user3007260
user3007260

Reputation: 1

How to save multiple similar(hierachical format) string with less memory?

I need save such strings in c++, and need do name compare. Is there any algorithm to reduce the memory usage? Thanks.

x1.x2.x3.r1 //typical string lenth is larger than 50.

x1.x2.x3.r2

x1.x2.x3.r3

x1.x2.x4.r1

...

Myself have such plan: divid a string to two parts: "x1.x2.x3.r1" = "x1.x2.x3." ( A ) + "r1"(B), and A can be used in other string. And when compare name need compare two parts. I am not sure if it can work.

Upvotes: 0

Views: 41

Answers (1)

Bartlomiej Lewandowski
Bartlomiej Lewandowski

Reputation: 11180

How about storing them in a tree?

Each node, would represent the next part of the string separated by a dot.

Then, when comparing, you compare the nodes ancestors.

Upvotes: 1

Related Questions