• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:59
CEST 13:59
KST 20:59
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL21] Ro16 Preview Pt2: All Star10Team Liquid Map Contest #22 - The Finalists14[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0
Community News
2026 GSL Season 1 Qualifiers12Maestros of the Game 2 announced52026 GSL Tour plans announced14Weekly Cups (April 6-12): herO doubles, "Villains" prevail1MaNa leaves Team Liquid23
StarCraft 2
General
MaNa leaves Team Liquid Maestros of the Game 2 announced 2026 GSL Tour plans announced Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Team Liquid Map Contest #22 - The Finalists
Tourneys
2026 GSL Season 1 Qualifiers GSL CK: More events planned pending crowdfunding RSL Revival: Season 5 - Qualifiers and Main Event Sparkling Tuna Cup - Weekly Open Tournament Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 522 Flip My Base The PondCast: SC2 News & Results Mutation # 521 Memorable Boss Mutation # 520 Moving Fees
Brood War
General
https://www.facebook.com/IonShieldAirPurifier/ ASL21 Strategy, Pimpest Plays Discussions [ASL21] Ro16 Preview Pt2: All Star Data needed BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL21] Ro16 Group D [ASL21] Ro16 Group C [ASL21] Ro16 Group B [Megathread] Daily Proleagues
Strategy
Simple Questions, Simple Answers What's the deal with APM & what's its true value Any training maps people recommend? Fighting Spirit mining rates
Other Games
General Games
Dawn of War IV Starcraft Tabletop Miniature Game Nintendo Switch Thread General RTS Discussion Thread Battle Aces/David Kim RTS Megathread
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread McBoner: A hockey love story Cricket [SPORT]
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Sexual Health Of Gamers
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1209 users

The Big Programming Thread - Page 625

Forum Index > General Forum
Post a Reply
Prev 1 623 624 625 626 627 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
April 30 2015 02:07 GMT
#12481
When you are using a javascript compiler like yui/closure to minify and concatenate your Javascript files in your prod build, how do you handle referencing the files in your source? So when you're doing dev you have file1.js, file2.js, file3.js, and in prod you have only single file compiled.js.

RIP GOMTV. RIP PROLEAGUE.
Neo7
Profile Blog Joined November 2007
United States922 Posts
April 30 2015 02:36 GMT
#12482
I'd throw the references into some template. Use a developer mode flag to determine whether to import the template file or reference the production js file based on what environment you're in.
It takes an idiot to do cool things.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
April 30 2015 04:59 GMT
#12483
On April 30 2015 11:36 Neo7 wrote:
I'd throw the references into some template. Use a developer mode flag to determine whether to import the template file or reference the production js file based on what environment you're in.


Hmm ya I must be missing something basic. So there's a few things.
1. Servlet app
2. Frontend is backbone js using requirejs.
3. App is built using ant.

So the first thing that's tripping me up is - even just concatening all the files happens as one of the tasks before the war task. So trying to see how to get those files to be included into the war. Then need to see how to best minify the javascript without breaking stuff and renaming all the references. I'd prefer to do it all through ant just to keep the build simpler but not sure if that's worth it if this is much easier in something like Grunt. I'd rather not install node just to build stuff.
RIP GOMTV. RIP PROLEAGUE.
Isualin
Profile Joined March 2011
Germany1903 Posts
April 30 2015 07:02 GMT
#12484
Microsoft reveals visual studio code It's own site doesn't load for me though. I am using eclipse for java, sublime for everything else right now but i might give it a try
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
Manit0u
Profile Blog Joined August 2004
Poland17730 Posts
Last Edited: 2015-04-30 09:53:34
April 30 2015 09:51 GMT
#12485
I need a bit of help with MySQL...

What I have:
A table where rows can have a one-to-one relation with other rows in the same table.

What I need:
Get all the rows that either don't have the relation, or if they do I want to only return one side of it.

Where I'm at now:

/*
* relation:
* inversedBy: otherSide
* otherSide:
* mappedBy: relation
*/
SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a
LEFT JOIN a.otherSide AS b
WHERE b.relation IS NULL


What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation.

Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL.
Time is precious. Waste it wisely.
ZenithM
Profile Joined February 2011
France15952 Posts
Last Edited: 2015-04-30 10:15:00
April 30 2015 10:11 GMT
#12486
On April 30 2015 16:02 Isualin wrote:
Microsoft reveals visual studio code It's own site doesn't load for me though. I am using eclipse for java, sublime for everything else right now but i might give it a try

It should work now. I don't think VS Code can replace a dedicated IDE like Eclipse yet (for example, when I tried it, I didn't see any "project" notion of any sort), but I'm sure it's part of their strategy to bring the full VS to other platforms. I would see it more as a replacement for, please, don't burn me, emacs, vim, kate, gedit (lol), etc etc.. :D
berated-
Profile Blog Joined February 2007
United States1134 Posts
April 30 2015 11:16 GMT
#12487
On April 30 2015 18:51 Manit0u wrote:
I need a bit of help with MySQL...

What I have:
A table where rows can have a one-to-one relation with other rows in the same table.

What I need:
Get all the rows that either don't have the relation, or if they do I want to only return one side of it.

Where I'm at now:

/*
* relation:
* inversedBy: otherSide
* otherSide:
* mappedBy: relation
*/
SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a
LEFT JOIN a.otherSide AS b
WHERE b.relation IS NULL


What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation.

Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL.


Use a union? I think thats what you want..

https://dev.mysql.com/doc/refman/5.0/en/union.html
Acrofales
Profile Joined August 2010
Spain18266 Posts
Last Edited: 2015-04-30 11:51:11
April 30 2015 11:35 GMT
#12488
On April 30 2015 20:16 berated- wrote:
Show nested quote +
On April 30 2015 18:51 Manit0u wrote:
I need a bit of help with MySQL...

What I have:
A table where rows can have a one-to-one relation with other rows in the same table.

What I need:
Get all the rows that either don't have the relation, or if they do I want to only return one side of it.

Where I'm at now:

/*
* relation:
* inversedBy: otherSide
* otherSide:
* mappedBy: relation
*/
SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a
LEFT JOIN a.otherSide AS b
WHERE b.relation IS NULL


What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation.

Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL.


Use a union? I think thats what you want..

https://dev.mysql.com/doc/refman/5.0/en/union.html

Yeah. Union should do it. Write a second query to get your other results and UNION them:

(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a LEFT JOIN table AS b ON a.relation = b.otherSide
WHERE b.relation IS NULL)
UNION
(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a INNER JOIN table AS b ON a.relation = b.otherSide)


I also don't really understand what was happening in your original query, so I think I fixed it.

That said, this seems like a pretty bad way of modeling this relationship, because there is no way of enforcing the 1-1.0 relationship. Instead, remove the otherSide (it is unnecessary), and add a UNIQUE constraint on relation. I am not sure MySQL allows a foreign key to the same table. If it does, add that one in as well, and you are guaranteed your 1-1,0 relationship.
berated-
Profile Blog Joined February 2007
United States1134 Posts
Last Edited: 2015-04-30 12:23:39
April 30 2015 12:19 GMT
#12489
On April 30 2015 20:35 Acrofales wrote:
Show nested quote +
On April 30 2015 20:16 berated- wrote:
On April 30 2015 18:51 Manit0u wrote:
I need a bit of help with MySQL...

What I have:
A table where rows can have a one-to-one relation with other rows in the same table.

What I need:
Get all the rows that either don't have the relation, or if they do I want to only return one side of it.

Where I'm at now:

/*
* relation:
* inversedBy: otherSide
* otherSide:
* mappedBy: relation
*/
SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a
LEFT JOIN a.otherSide AS b
WHERE b.relation IS NULL


What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation.

Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL.


Use a union? I think thats what you want..

https://dev.mysql.com/doc/refman/5.0/en/union.html

Yeah. Union should do it. Write a second query to get your other results and UNION them:

(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a LEFT JOIN table AS b ON a.relation = b.otherSide
WHERE b.relation IS NULL)
UNION
(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a INNER JOIN table AS b ON a.relation = b.otherSide)


I also don't really understand what was happening in your original query, so I think I fixed it.

That said, this seems like a pretty bad way of modeling this relationship, because there is no way of enforcing the 1-1.0 relationship. Instead, remove the otherSide (it is unnecessary), and add a UNIQUE constraint on relation. I am not sure MySQL allows a foreign key to the same table. If it does, add that one in as well, and you are guaranteed your 1-1,0 relationship.


I think you might have flipped the condition a.other side not b.other side. If b.relation being null means it didn't join, then I would think it would be in the join. either way thats why I didn't elaborate and just left it at use union
Acrofales
Profile Joined August 2010
Spain18266 Posts
April 30 2015 12:32 GMT
#12490
On April 30 2015 21:19 berated- wrote:
Show nested quote +
On April 30 2015 20:35 Acrofales wrote:
On April 30 2015 20:16 berated- wrote:
On April 30 2015 18:51 Manit0u wrote:
I need a bit of help with MySQL...

What I have:
A table where rows can have a one-to-one relation with other rows in the same table.

What I need:
Get all the rows that either don't have the relation, or if they do I want to only return one side of it.

Where I'm at now:

/*
* relation:
* inversedBy: otherSide
* otherSide:
* mappedBy: relation
*/
SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a
LEFT JOIN a.otherSide AS b
WHERE b.relation IS NULL


What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation.

Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL.


Use a union? I think thats what you want..

https://dev.mysql.com/doc/refman/5.0/en/union.html

Yeah. Union should do it. Write a second query to get your other results and UNION them:

(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a LEFT JOIN table AS b ON a.relation = b.otherSide
WHERE b.relation IS NULL)
UNION
(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a INNER JOIN table AS b ON a.relation = b.otherSide)


I also don't really understand what was happening in your original query, so I think I fixed it.

That said, this seems like a pretty bad way of modeling this relationship, because there is no way of enforcing the 1-1.0 relationship. Instead, remove the otherSide (it is unnecessary), and add a UNIQUE constraint on relation. I am not sure MySQL allows a foreign key to the same table. If it does, add that one in as well, and you are guaranteed your 1-1,0 relationship.


I think you might have flipped the condition a.other side not b.other side. If b.relation being null means it didn't join, then I would think it would be in the join. either way thats why I didn't elaborate and just left it at use union


You're probably right. It should be WHERE b.otherSide IS NULL. What the LEFT OUTER JOIN (same as LEFT JOIN) query does is to join every row in a with every row in b that matches the ON criteria. If there is no ON criteria it is simply a Cartesian product (as in the original query given, which I think is wrong for that reason). If there is an ON criteria then, if there is a row in a that has no matching result in b, these are left blank (null).

Now that I think about it, I am not sure why we are joining in the first query at all. Shouldn't:


SELECT id AS id, (val * 0.10) AS value
FROM table WHERE related IS NULL


work just fine?
Manit0u
Profile Blog Joined August 2004
Poland17730 Posts
Last Edited: 2015-04-30 12:42:40
April 30 2015 12:41 GMT
#12491
On April 30 2015 21:32 Acrofales wrote:
Show nested quote +
On April 30 2015 21:19 berated- wrote:
On April 30 2015 20:35 Acrofales wrote:
On April 30 2015 20:16 berated- wrote:
On April 30 2015 18:51 Manit0u wrote:
I need a bit of help with MySQL...

What I have:
A table where rows can have a one-to-one relation with other rows in the same table.

What I need:
Get all the rows that either don't have the relation, or if they do I want to only return one side of it.

Where I'm at now:

/*
* relation:
* inversedBy: otherSide
* otherSide:
* mappedBy: relation
*/
SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a
LEFT JOIN a.otherSide AS b
WHERE b.relation IS NULL


What this gives me is all the rows without the relation. Now I need to get this other side of the relation (inverse side is the owning side) for those that have it, and it has to be included in all the id, value etc. in the results on equal terms as rows without relation.

Help anyone? I've been churning this around so much that my brain boils and I don't know what I'm talking about any more. And I suck horribly at SQL.


Use a union? I think thats what you want..

https://dev.mysql.com/doc/refman/5.0/en/union.html

Yeah. Union should do it. Write a second query to get your other results and UNION them:

(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a LEFT JOIN table AS b ON a.relation = b.otherSide
WHERE b.relation IS NULL)
UNION
(SELECT a.id AS id, (a.val * 0.10) AS value
FROM table AS a INNER JOIN table AS b ON a.relation = b.otherSide)


I also don't really understand what was happening in your original query, so I think I fixed it.

That said, this seems like a pretty bad way of modeling this relationship, because there is no way of enforcing the 1-1.0 relationship. Instead, remove the otherSide (it is unnecessary), and add a UNIQUE constraint on relation. I am not sure MySQL allows a foreign key to the same table. If it does, add that one in as well, and you are guaranteed your 1-1,0 relationship.


I think you might have flipped the condition a.other side not b.other side. If b.relation being null means it didn't join, then I would think it would be in the join. either way thats why I didn't elaborate and just left it at use union


You're probably right. It should be WHERE b.otherSide IS NULL. What the LEFT OUTER JOIN (same as LEFT JOIN) query does is to join every row in a with every row in b that matches the ON criteria. If there is no ON criteria it is simply a Cartesian product (as in the original query given, which I think is wrong for that reason). If there is an ON criteria then, if there is a row in a that has no matching result in b, these are left blank (null).

Now that I think about it, I am not sure why we are joining in the first query at all. Shouldn't:


SELECT id AS id, (val * 0.10) AS value
FROM table WHERE related IS NULL


work just fine?


Tried that, it threw exceptions in the DBAL about you needing explicit joins etc.

Anyway, I've solved the issue by simply making 2 queries instead of 1 and then merging the results.

And I know it's badly designed relationship but I'm fixing client's old system where table rows have 200+ columns of which 30 are various relations to itself and other things. Nightmare.
Time is precious. Waste it wisely.
Artesimo
Profile Joined February 2015
Germany571 Posts
Last Edited: 2015-04-30 13:14:53
April 30 2015 13:02 GMT
#12492
Hey guys it is me again. first of all, thanks for pointing me towards regex, I've been playing around with it since then, its really fun to fuck around with data use it to search data.

At the moment I am trying to search/organize itemlists from a small game a friend of mine is making at the moment and therefore gets constant changes. I want to be able to read in the file when I start my programm, then search for items of certain criteria. the list is from the following structure(with more columns but that shouldnt matter)


#################################
A##########Area#################A
#################################
[itemID] [tags] [value]
----------------------------------------------------------
sword slash slash 112G
one-handed
spear pointy 50G
throwable
.
.
.
.
(the entrys of each colums are all algined, for some reason I dont manage to display it properly in this post.
I wantet to share my ideas/problems. I already have a working solution, but I feel like it doesnt satisfy me.
Current status:
+ Show Spoiler +
I am using regex to split the columns and then sort them into vectors, one vector for each columns and store them in a main vector. If I search now for a name/tag/min or maxvalue, it runs through the corresponding vector until it finds this vector and then checks the other vectors for the values thats in them, at last comparing it to the first vector where the name columns is stored including the empty rows. My thought was that since every item can have multiple tags/attributes but only has one name, it checks the name vector for previous/later/same row occurances of a name which then tells me that everything between the first and the last row in which a name occured must belong to the first found name, therefore displaying all the corresponding values. However, I feel like there must be a better way to do this.


First of all: is there a better way to read in tables that are stored in a txt-file with c++ standard library?

What would be a better way to seperate the values then a regexsearch? Whitespaces as delimiters for getline() wont work since the number of whitespaces varys. I assume that regex is compared to this small task overkill and not really an performant solution(even though I am just searching for multiple occurances of ' ').

Storing vectors in vectors in vectors... this babushka-style seems pretty ugly. During my research I came across the term "linked lists", should I continue checking this out for this matter(I will check it out anyways later, but at the moment I just care about this task)?

EDIT: Also, since I start to get really serious about programming, is there a styleguide/general compiliation of things I should whatch out for while coding, specificly in c++, thats actual used in the working world? I am planning to do my first internship after my third semester/maybe even after this one if I get lucky and I would really like to show off something thats actually usefull for the company so that I am not just some student that you have to babysit the first few weeks.
netherh
Profile Blog Joined November 2011
United Kingdom333 Posts
April 30 2015 14:26 GMT
#12493
I'm not sure there's any "good" way to read in a file format like that. Can you persuade your friend to use xml or json or lua... some actual data description language? (It'll be easier for him in the long run too).
Ropid
Profile Joined March 2009
Germany3557 Posts
April 30 2015 14:33 GMT
#12494
So, "regular expressions" do have limitations, and here you need to switch between using different ones depending on what you think will come next in your file. Your problem here is simple, so you can get away by not thinking much and just doing it by nose.

Like, you first think "the start of the file can have comments... let's check for that and throw those lines away". After you've done that, you'll be in the next section of the input file, and you'll also be in the next section of your program code where you'll use different regex etc. Something like this is called a "parser".

You can just hack something together here without a system, but while you are motivated because you have an actual problem, you might want to look around a bit to see how this can be done generally.

To write a parser, I believe there's nothing in the C++ standard library that will help you generate it. You could search around to see if you can find a simple parser library. You can also write the parser yourself, and I think you should do this manually at least once to see how it can be done.

If you've never seen the syntax of a language drawn as a diagram, type "backus-naur grammar diagram" in Google's Image Search and look at what you find. You can understand those just by looking at it. You could draw something similar for your problem on paper. In the next step, you basically just stupidly translate every box you've drawn into a piece of code. The arrows in the diagram will turn into control structures like if/then/else and loops or recursion. That's what the parser libraries would do for you. You feed them with a description of your diagram and they'll generate the program's structure automatically.
"My goal is to replace my soul with coffee and become immortal."
Artesimo
Profile Joined February 2015
Germany571 Posts
Last Edited: 2015-04-30 14:54:57
April 30 2015 14:33 GMT
#12495
On April 30 2015 23:26 netherh wrote:
I'm not sure there's any "good" way to read in a file format like that. Can you persuade your friend to use xml or json or lua... some actual data description language? (It'll be easier for him in the long run too).


Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ). You think I should stick with my regex-approach? What about the vector-stuff, should I search for a better container or does my method of stacking vectors just seem unintuitive to me because I am not used to it? At the moment I fondled a little bit around with "map", since it could let me get rid of the multiple vectors and also give me an ability to store the locations of said items on top of the values that belong to them.

EDIT: Thanks ropid, I can assure you that I already solved the problem using regex before asking for help. I was just searching for optimization since it felt a little overkill since my iterator has to check on every word "does it has letters? yes? good. does a single space come afterwards and then more letters? must be a multiple-words name/attribute then. does it start with a number? good, get it, grab it all and split it up. oh, it is just spaces? just ignore the findings and put a blank in the names-vector for that line". Sometimes I have problems understanding what is "hard" for a machine and whats not^^.


EDIT2: I figured a linked list is what I propably want and most likely would be the "most professional" thing to store this. I am going to use vector first until someone advices me otherwise. In addition, here is a chart of what I am planing to do:
[image loading]
Ropid
Profile Joined March 2009
Germany3557 Posts
Last Edited: 2015-04-30 15:07:09
April 30 2015 14:54 GMT
#12496
Well, then you basically already understand it. The parser libraries/generators are just something that will take over that work you described. Thinking about the grammar's syntax is just a lot less work than thinking about the actual code needed. It especially helps when you have to do changes later. The downside is you have to learn how to use the parser library.

EDIT: Also, you are right in thinking that this is hard for the machine. It has to test and branch at every single step while eating through the input stream of characters, and every branch can make it wipe out all the work it had already prepared for the following instructions. It's one of the things that can slow it down a lot.
"My goal is to replace my soul with coffee and become immortal."
netherh
Profile Blog Joined November 2011
United Kingdom333 Posts
Last Edited: 2015-04-30 15:35:32
April 30 2015 15:25 GMT
#12497
On April 30 2015 23:33 Artesimo wrote:
Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ). You think I should stick with my regex-approach? What about the vector-stuff, should I search for a better container or does my method of stacking vectors just seem unintuitive to me because I am not used to it? At the moment I fondled a little bit around with "map", since it could let me get rid of the multiple vectors and also give me an ability to store the locations of said items on top of the values that belong to them.


Well, I'm sure there are Java libraries for reading xml / json.

The correct container generally depends on your interface needs, and then on your usage pattern.
Vectors have fast iteration (contiguous memory), but slow insertion / deletion (except from the end).
Lists have fast insertion / deletion, but slower iteration. (In practice vectors may still be faster where the container has few items).

Other container types exist for other purposes / usage patterns: e.g.
Queues, Deques, Priority Queues, Maps, Multimaps, Unordered Maps, Sets, Multisets, Unordered Sets.

EDIT: I'm not quite sure what your diagram is supposed to represent, but I'd be inclined to structure things like this:



struct Item
{
std::vector<std::string> tags;
unsigned int price;
};

struct Location
{
std::vector<Item> items;
};


Artesimo
Profile Joined February 2015
Germany571 Posts
April 30 2015 15:41 GMT
#12498
+ Show Spoiler +
On May 01 2015 00:25 netherh wrote:
Show nested quote +
On April 30 2015 23:33 Artesimo wrote:
Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ). You think I should stick with my regex-approach? What about the vector-stuff, should I search for a better container or does my method of stacking vectors just seem unintuitive to me because I am not used to it? At the moment I fondled a little bit around with "map", since it could let me get rid of the multiple vectors and also give me an ability to store the locations of said items on top of the values that belong to them.


Well, I'm sure there are Java libraries for reading xml / json.

The correct container generally depends on your interface needs, and then on your usage pattern.
Vectors have fast iteration (contiguous memory), but slow insertion / deletion (except from the end).
Lists have fast insertion / deletion, but slower iteration. (In practice vectors may still be faster where the container has few items).

Other container types exist for other purposes / usage patterns: e.g.
Queues, Deques, Priority Queues, Maps, Multimaps, Unordered Maps, Sets, Multisets, Unordered Sets.

EDIT: I'm not quite sure what your diagram is supposed to represent, but I'd be inclined to structure things like this:



struct Item
{
std::vector<std::string> tags;
unsigned int price;
};

struct Location
{
std::vector<Item> items;
};




Haha, as usual... you solution is so much simpler than what my crude brain thought about, thanks alot.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
April 30 2015 16:42 GMT
#12499
On April 30 2015 23:33 Artesimo wrote:
Show nested quote +
On April 30 2015 23:26 netherh wrote:
I'm not sure there's any "good" way to read in a file format like that. Can you persuade your friend to use xml or json or lua... some actual data description language? (It'll be easier for him in the long run too).


Unfortunately he only codes in java since its the only thing he knows. He also does it as a hobby since his work isnt related to IT in any form (even though he still is better than me at coding... for now ). You think I should stick with my regex-approach? What about the vector-stuff, should I search for a better container or does my method of stacking vectors just seem unintuitive to me because I am not used to it? At the moment I fondled a little bit around with "map", since it could let me get rid of the multiple vectors and also give me an ability to store the locations of said items on top of the values that belong to them.

EDIT: Thanks ropid, I can assure you that I already solved the problem using regex before asking for help. I was just searching for optimization since it felt a little overkill since my iterator has to check on every word "does it has letters? yes? good. does a single space come afterwards and then more letters? must be a multiple-words name/attribute then. does it start with a number? good, get it, grab it all and split it up. oh, it is just spaces? just ignore the findings and put a blank in the names-vector for that line". Sometimes I have problems understanding what is "hard" for a machine and whats not^^.


EDIT2: I figured a linked list is what I propably want and most likely would be the "most professional" thing to store this. I am going to use vector first until someone advices me otherwise. In addition, here is a chart of what I am planing to do:
[image loading]

If you're using Java, check out the String Tokenizer class. It makes parsing so much easier. It reads much more like you or I do, and not character-by-character.

If you also have to stick with putting your data in .txt's, I recommend designing the file with the Name Value Pair paradigm in mind. Basically you'll have a bunch of lines of the form " [item] x = [value] y". Its pretty simple to parse, and can be extended to do some pretty powerful stuff.
Who called in the fleet?
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
April 30 2015 16:46 GMT
#12500
On April 30 2015 06:51 darkness wrote:
Java is a really good language with really good syntax for beginners. As soon as you want to have more control, Java becomes terrible. No deterministic destructor (finalize is unreliable), no deterministic memory deallocation, no pass by reference unless you pass an object. C# solves that by having 'ref' and 'out' though. In a way, C# seems like better or more advanced Java.

None of these are things I'd name as positive aspects of C#. Stay away from ref and out if possible. Don't hesitate to introduce a small class instead. Don't use C# or Java in settings where you would need deterministic object lifetime.
If you have a good reason to disagree with the above, please tell me. Thank you.
Prev 1 623 624 625 626 627 1032 Next
Please log in or register to reply.
Live Events Refresh
Afreeca Starleague
10:00
Ro16 Group D
Barracks vs Leta
Royal vs Light
Afreeca ASL 17266
StarCastTV_EN386
Liquipedia
GSL
08:00
2026 Season 1: Qualifiers
herO vs Rogue
Maru vs SHINLIVE!
Solar vs Zoun
Cure vs TriGGeR
IntoTheiNu 426
CranKy Ducklings SOOP205
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko247
TKL 151
Rex 29
StarCraft: Brood War
Britney 26143
Calm 14343
Jaedong 6379
Sea 5808
BeSt 1595
Rush 1149
Horang2 829
Pusan 497
Mind 340
Zeus 263
[ Show more ]
Hyuk 239
JYJ 180
Larva 157
ToSsGirL 119
Sharp 117
ggaemo 86
Sexy 56
[sc1f]eonzerg 53
Sea.KH 52
Killer 29
Bale 27
Noble 25
Shine 22
Icarus 18
SilentControl 18
GoRush 12
Sacsri 11
JulyZerg 10
Movie 9
Terrorterran 6
eros_byul 1
Dota 2
Gorgc4312
League of Legends
Reynor57
Counter-Strike
zeus1190
x6flipin515
shoxiejesuss423
edward302
markeloff134
Super Smash Bros
Mew2King123
Heroes of the Storm
Trikslyr122
Other Games
singsing2057
B2W.Neo375
Happy287
crisheroes253
XaKoH 216
QueenE51
Organizations
Dota 2
PGL Dota 2 - Main Stream6667
PGL Dota 2 - Secondary Stream6276
StarCraft: Brood War
UltimateBattle 316
StarCraft 2
WardiTV54
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• StrangeGG 3
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• TFBlade1518
Upcoming Events
WardiTV Map Contest Tou…
31m
herO vs Classic
SHIN vs Cure
Solar vs Percival
RSL Revival
22h 1m
Replay Cast
1d 12h
The PondCast
1d 22h
KCM Race Survival
1d 22h
WardiTV Map Contest Tou…
1d 23h
Gerald vs TBD
Clem vs TBD
ByuN vs TBD
Rogue vs MaxPax
ShoWTimE vs TBD
CranKy Ducklings
2 days
Escore
2 days
RSL Revival
3 days
WardiTV Map Contest Tou…
3 days
[ Show More ]
Universe Titan Cup
3 days
Rogue vs Percival
Ladder Legends
4 days
uThermal 2v2 Circuit
4 days
BSL
4 days
Sparkling Tuna Cup
4 days
WardiTV Map Contest Tou…
4 days
Ladder Legends
5 days
BSL
5 days
Replay Cast
5 days
Replay Cast
5 days
Wardi Open
5 days
Monday Night Weeklies
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-04-20
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
WardiTV TLMC #16
Nations Cup 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W4
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
RSL Revival: Season 5
2026 GSL S1
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.