• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 17:44
CEST 23:44
KST 06:44
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL51Weekly Cups (June 23-29): Reynor in world title form?12FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
Statistics for vetoed/disliked maps The SCII GOAT: A statistical Evaluation The GOAT ranking of GOAT rankings How does the number of casters affect your enjoyment of esports? Esports World Cup 2025 - Final Player Roster
Tourneys
Korean Starcraft League Week 77 Master Swan Open (Global Bronze-Master 2) RSL: Revival, a new crowdfunded tournament series [GSL 2025] Code S: Season 2 - Semi Finals & Finals $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Flash Announces Hiatus From ASL Player “Jedi” cheat on CSL Unit and Spell Similarities Help: rep cant save
Tourneys
[Megathread] Daily Proleagues [BSL20] Grand Finals - Sunday 20:00 CET Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Things Aren’t Peaceful in Palestine Trading/Investing Thread US Politics Mega-thread Russo-Ukrainian War Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 634 users

The Big Programming Thread - Page 625

Forum Index > General Forum
Post a Reply
Prev 1 623 624 625 626 627 1031 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
Poland17243 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
Spain17970 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
Spain17970 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
Poland17243 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
Germany546 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
Germany546 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
Germany546 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 5h 16m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 203
JuggernautJason122
ProTech84
StarCraft: Brood War
Calm 2558
Dewaltoss 120
ZZZero.O 96
NaDa 20
Shine 15
MaD[AoV]5
Dota 2
capcasts132
NeuroSwarm42
League of Legends
JimRising 629
Counter-Strike
flusha842
Foxcn293
taco 183
Heroes of the Storm
Liquid`Hasu538
Other Games
summit1g6376
Grubby3653
tarik_tv2971
FrodaN1790
fl0m832
ZombieGrub218
Pyrionflax167
ViBE129
Sick81
PPMD34
mouzStarbuck2
Organizations
Other Games
BasetradeTV42
StarCraft 2
angryscii 23
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• RyuSc2 53
• davetesta43
• LUISG 15
• IndyKCrew
• sooper7s
• Migwel
• AfreecaTV YouTube
• intothetv
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21430
League of Legends
• Doublelift6174
• Jankos3770
Other Games
• Scarra1139
• imaqtpie788
• Shiphtur295
Upcoming Events
Korean StarCraft League
5h 16m
CranKy Ducklings
12h 16m
RSL Revival
12h 16m
ByuN vs Cham
herO vs Reynor
FEL
18h 16m
RSL Revival
1d 12h
Clem vs Classic
SHIN vs Cure
FEL
1d 14h
BSL: ProLeague
1d 20h
Dewalt vs Bonyth
Replay Cast
3 days
Sparkling Tuna Cup
3 days
The PondCast
4 days
[ Show More ]
Replay Cast
5 days
RSL Revival
5 days
Replay Cast
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.