• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 19:47
CET 01:47
KST 09:47
  • 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
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t StarCraft, SC2, HotS, WC3, Returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win
Tourneys
Constellation Cup - Main Event - Stellar Fest Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle [ASL20] Ask the mapmakers — Drop your questions BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Where's CardinalAllin/Jukado the mapmaker?
Tourneys
[ASL20] Grand Finals [BSL21] RO32 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO32 Group B - Sunday 21:00 CET
Strategy
PvZ map balance Current Meta How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine The Games Industry And ATVI US Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
Formula 1 Discussion 2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Learning my new SC2 hotkey…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1035 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
Poland17421 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
Spain18112 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
Spain18112 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
Poland17421 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
Germany563 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
Germany563 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
Germany563 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
OSC
23:00
OSC Elite Rising Star #17
ReBellioN vs HiGhDrA
Shameless vs Demi
LetaleX vs Mute
Percival vs TBD
CranKy Ducklings100
Liquipedia
BSL 21
20:00
ProLeague - RO32 Group B
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
ZZZero.O106
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
White-Ra 314
ProTech122
UpATreeSC 66
Ketroc 21
StarCraft: Brood War
Artosis 740
ZZZero.O 106
NaDa 25
Super Smash Bros
hungrybox1456
Other Games
Grubby2922
summit1g941
fl0m555
Maynarde133
JuggernautJason11
Organizations
Other Games
gamesdonequick1470
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Hupsaiya 84
• RyuSc2 50
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• blackmanpl 20
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21115
League of Legends
• imaqtpie3228
Other Games
• Scarra640
Upcoming Events
OSC
8h 13m
Wardi Open
11h 13m
Wardi Open
15h 13m
Replay Cast
22h 13m
WardiTV Korean Royale
1d 11h
Replay Cast
2 days
Kung Fu Cup
2 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
2 days
The PondCast
3 days
RSL Revival
3 days
Solar vs Zoun
MaxPax vs Bunny
[ Show More ]
Kung Fu Cup
3 days
WardiTV Korean Royale
3 days
Replay Cast
3 days
RSL Revival
4 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
4 days
CranKy Ducklings
5 days
RSL Revival
5 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
5 days
BSL 21
5 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
6 days
RSL Revival
6 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
BSL 21
6 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
Liquipedia Results

Completed

Proleague 2025-11-07
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
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.