• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 20:40
CET 02:40
KST 10:40
  • 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
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2
StarCraft 2
General
ComeBackTV's documentary on Byun's Career ! Team TLMC #5: Winners Announced! What's the best tug of war? The Grack before Christmas Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies
Tourneys
OSC Season 13 World Championship $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament Winter Warp Gate Amateur Showdown #1
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play
Brood War
General
What are former legends up to these days? BW General Discussion How soO Began His ProGaming Dreams Klaucher discontinued / in-game color settings BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [BSL21] LB SemiFinals - Saturday 21:00 CET [BSL21] WB & LB Finals - Sunday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread Beyond All Reason Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread 12 Days of Starcraft The Games Industry And ATVI Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced Where to ask questions and add stream?
Blogs
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1563 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
Poland17548 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
Spain18159 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
Spain18159 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
Poland17548 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
Germany564 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
Germany564 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
Germany564 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
Next event in 7h 21m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason123
StarCraft: Brood War
Britney 14669
Artosis 830
Dewaltoss 97
Shuttle 88
Bale 34
Dota 2
syndereN775
NeuroSwarm131
League of Legends
C9.Mang0261
Other Games
tarik_tv6097
fl0m811
JimRising 434
Maynarde141
Mew2King76
minikerr56
Organizations
Other Games
gamesdonequick1533
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• imaqtpie3391
• Scarra1583
Upcoming Events
Replay Cast
7h 21m
Wardi Open
10h 21m
OSC
1d 10h
Solar vs MaxPax
ByuN vs Krystianer
Spirit vs TBD
OSC
4 days
Korean StarCraft League
5 days
OSC
5 days
OSC
5 days
OSC
6 days
uThermal 2v2 Circuit
6 days
Liquipedia Results

Completed

CSL Season 19: Qualifier 2
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL Season 21
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1: W2
Escore Tournament S1: W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
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 © 2025 TLnet. All Rights Reserved.