• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:15
CET 19:15
KST 03:15
  • 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 Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
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 What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion Brood War web app to calculate unit interactions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 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
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 Russo-Ukrainian War Thread US Politics Mega-thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion 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
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2038 users

The Big Programming Thread - Page 824

Forum Index > General Forum
Post a Reply
Prev 1 822 823 824 825 826 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.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
January 03 2017 19:02 GMT
#16461
hey I'm tinkering with a little chat client that writes to stdout and gets server messages from stdin and I'm interacting with this through a QT gui that basically runs a Qprocess that gets the client as a process, reads the output and can write to the input. Now my problem is, how do I get a list of active users to the Qt window? I've only got the client input and output stream.

Do I make another process that gets the user list from the server and sends this back to the gui? That sounds somewhat complicated.
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
Last Edited: 2017-01-03 19:45:27
January 03 2017 19:43 GMT
#16462
instead of interpreting all data from stdin and stdout as messages, use them as a comm channel that carries different types of data?


in json format:

{ "type": "message", "content": "hello!" } or

{ "type": "userList", "content": "Alice, John" }
Age of Mythology forever!
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2017-01-03 19:53:16
January 03 2017 19:52 GMT
#16463
that's what I also thought about, but isn't that prone to bugs if someone would send a text message that accidentally has the wrong structure? (although probably unlikely)
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
January 03 2017 19:59 GMT
#16464
you would take everything the user typed literally and put it in content field, why would there be a bug?

this is similar to the way that all web requests work, only difference is you are using stdin/stdout instead of a tcp connection
Age of Mythology forever!
Nyxisto
Profile Joined August 2010
Germany6287 Posts
January 03 2017 20:15 GMT
#16465
yes, you're right. I was confused and thought that there might be a way how a user could act like he's sending a "userlist" message but that shouldn't be possible. I'll do that, thanks.
Manit0u
Profile Blog Joined August 2004
Poland17433 Posts
Last Edited: 2017-01-03 21:23:54
January 03 2017 21:16 GMT
#16466
On January 04 2017 02:27 tofucake wrote:
Old datatables was awful. New datatables is pretty nice


Have you ever tried them alongside materialize with responsive tables?

I'm living in a nightmare for the past few days. I've even solved the async mailer library being incompatible with user authentication library problem just to get out of this shit for a moment...

Edit:

I mean, why the fuck in this day and age they would go for changing the style attribute of column cells and setting their width in pixel values, along with absolute positioning everywhere? What in the actual fuck?! How am I supposed to work with this shit that just pretends to be responsive? (I'm using DataTables 1.10.10)

The funniest thing is, including the DataTables.responsive extras and doing responsive: true, in the set-up actually makes it worse.

Seriously, fuck that shit. Why don't front-end people rebel at such blatant violation of all good practices?
Time is precious. Waste it wisely.
Nyxisto
Profile Joined August 2010
Germany6287 Posts
Last Edited: 2017-01-05 01:00:01
January 04 2017 23:54 GMT
#16467
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-01-05 01:26:55
January 05 2017 00:57 GMT
#16468
On January 05 2017 08:54 Nyxisto wrote:
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?


I don't really understand your problem but everything you seem to be doing looks like enforcing a protocol for communicating within your network, and stuff like that already exists because it's common.

https://en.wikipedia.org/wiki/JSON-RPC
https://en.wikipedia.org/wiki/IRCd

Some of your other "problems" just seem like problems with C/C++ async design, which is to say pretty poor multi-threading - polling, disconnects, updates (assuming you're using C++ cause you used stdin).
There is no one like you in the universe.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 05 2017 01:19 GMT
#16469
On January 05 2017 08:54 Nyxisto wrote:
A new problem has cropped up in my chat client. The way this works at the moment is that I basically iterate over the sockets and if I receive anything the server will broadcast it, if some client is not available I'll catch that and drop the client from the socket list.

Problem is that this only updates if someone tries to send a message because that's the only time the sockets are being tested. My hacky solution was to basically generate a "quit key" that is being send to the server when the client quits the app. I assume there's some better way to do this?

What language do you use? What methods do you use to "test" your sockets?
Usually a socket should tell you when the connection has been closed. In java, for example, a TCP socket will throw an exeption when it discovers the other side is unavailable.
Manit0u
Profile Blog Joined August 2004
Poland17433 Posts
Last Edited: 2017-01-05 16:33:52
January 05 2017 06:32 GMT
#16470
I've decided to screw DataTables and implement my own solution.

Everything now works, is a lot simpler, a lot more maintainable and more reusable. It's also more than 6x faster.
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-01-05 19:43:53
January 05 2017 19:15 GMT
#16471
I am a bit confused about data structure complexity when it comes to iteration.

What is the difference between "iteration" and "search".

I understand that iteration means to go through each element 1 by 1.

For example on this page:

http://bigocheatsheet.com/

Hash Table has O(1) for "search". It uses the hashcode to find the element.

Array has O(n) for "search". in this case, is "search" the same as iteration?

If so, I am wondering how hash tables compare to other data structures in terms of iteration? Is iteration slower with a hashset because it likely contains empty buckets?



And does this mean that if I need a data structure where I have to iterate to find what I want, I should use an arraylist?
What I need to do is find elements based on criteria (not the element itself, just some field the element has). I then need to remove those elements. oh, and a map won't work because of the nature of the criteria


edit: (I realize that I am using hash table and hashset interchangeably here when they are different structures, but I am guessing it doesn't matter for iteration? if it does, why?)
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-05 19:53:37
January 05 2017 19:52 GMT
#16472
On January 06 2017 04:15 travis wrote:
I am a bit confused about data structure complexity when it comes to iteration.

What is the difference between "iteration" and "search".

I understand that iteration means to go through each element 1 by 1.

For example on this page:

http://bigocheatsheet.com/

Hash Table has O(1) for "search". It uses the hashcode to find the element.

Array has O(n) for "search". in this case, is "search" the same as iteration?

If so, I am wondering how hash tables compare to other data structures in terms of iteration? Is iteration slower with a hashset because it likely contains empty buckets?



And does this mean that if I need a data structure where I have to iterate to find what I want, I should use an arraylist?
What I need to do is find elements based on criteria (not the element itself, just some field the element has). I then need to remove those elements. oh, and a map won't work because of the nature of the criteria


edit: (I realize that I am using hash table and hashset interchangeably here when they are different structures, but I am guessing it doesn't matter for iteration? if it does, why?)

What that website refers to as "search" is probably a contains check for a given element. "Does the data structure contain a particular element?". This is something that all hash-based data structures are particularly good at since they have been made exactly for this purpose.

If you want to iterate over all elements within a data structure nothing will ever beat an array in terms of performance. ArrayList in java is using an array in the background and thus very fast for iterations. However, the HashMap (not HashTable!) also uses an array (more or less. Its complicated) and isnt that much slower. It should usually not make any difference. Dont worry about it unless you actually encounter problems with performance or you are explicitly working on an algorithm which needs to perform well for millions of elements.

The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.

By the way: A HashSet is usually build by using a HashMap internally so it really doesnt matter. Even if the Set is build from scratch it probably does much of the same thing as the Map. The difference, if any, should be insignificant.
slmw
Profile Blog Joined October 2010
Finland233 Posts
January 06 2017 01:35 GMT
#16473
On January 06 2017 04:52 RoomOfMush wrote:


The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.


I would say the logarithmic factor from a binary tree makes it a lot slower, and the empty buckets in hash sets slow things down as well. Neither of these data structures are 'tightly packed'.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 06 2017 10:33 GMT
#16474
On January 06 2017 10:35 slmw wrote:
Show nested quote +
On January 06 2017 04:52 RoomOfMush wrote:


The worst data structure for iterations is probably a linked list. This has nothing to do with the theoretic aspect of the linked list (since it is very good in theory!) but with the way modern hardware works. A linked list is very very hard to predict for the computer since each node could be at completely random points within the computers memory while an array traditionally has all of its elements tightly packed. Prediction is a big thing with hardware in modern times.


I would say the logarithmic factor from a binary tree makes it a lot slower, and the empty buckets in hash sets slow things down as well. Neither of these data structures are 'tightly packed'.

It is true that the empty buckets have an impact on speed, but in the average case the number of empty buckets is usually not very big. It still is an array iteration though (assuming the regular java HashMap implementation of course) and those are relatively fast.

But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.
zf
Profile Joined April 2011
231 Posts
January 06 2017 11:27 GMT
#16475
On January 06 2017 19:33 RoomOfMush wrote:
But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.


Average search time is logarithmic.
RoomOfMush
Profile Joined March 2015
1296 Posts
January 06 2017 12:39 GMT
#16476
On January 06 2017 20:27 zf wrote:
Show nested quote +
On January 06 2017 19:33 RoomOfMush wrote:
But why do you say iterating a binary tree has a logarithmic factor to it? The worst case for a binary tree is a linked list. I do not see how this would be anything but linear time.


Average search time is logarithmic.

But travis and I were talking about iterating all elements.
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2017-01-06 13:23:57
January 06 2017 13:05 GMT
#16477
Sorry, I meant binary search trees where most languages only provide an ordered iterator. I stand corrected.
Edit: Which is also O(N), so it's just the same as an in-order traversal of a tree. A few more steps involved than in iterating a linked list though.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-01-06 18:11:42
January 06 2017 17:18 GMT
#16478
edit:

i guess it would be rude to completely delete this. my question was about using recursion to find the smallest finite line segment among many finite line segments on a plane, that does not intersect any other line segments.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2017-01-06 17:45:05
January 06 2017 17:44 GMT
#16479
First of all you should sort your lines by length. There should be a sort-method readily available in Java, you might have to pass it a Comparer of sorts, which converts a line into its length. The result of this step is a sorted list of lines.

Then in the second step, you iterate over the sorted lines. For each line, you check it against all lines, which you do again by iterating over the sorted lines, skipping the one you're currently checking. If you find one that doesn't intersect any line, you return that one as a result. It is the smallest one because it's the first in the sorted list.

There is no recursion here. It's a naive approach, but clean and simple. It's O(n^2). More sophisticated approaches probably would keep the first part, but tweak the second part to use sort of a divide and conquer approach, but that won't be very simple at all. I can imagine O(n log n), but I don't know if it actually is possible.

This approach includes a number of pointless checks, in the worst case 50%. This is because I check against all lines without skipping the pairs already covered. We can avoid that easily by storing the sorted lines in a list, then iterate over the list by index. If we are currently at list[5], we only check against list[6] and beyond:

for(int i = 0; i < list.Count; ++i) {
for(int k = i + 1; k < list.Count; ++k) {
check if list[i] intersects list[k];
}
}
Still is O(n^2) though.

Always ask yourself if you can split your problem into smaller chunks. Sort first, check after. Simple approach first, optimization after.

Also Java or rather the JVM is not well equipped for heavy recursion. Don't avoid recursion at all costs, but if you're doing a lot of work with deep recursion, you probably should try to avoid it.
If you have a good reason to disagree with the above, please tell me. Thank you.
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2017-01-06 19:11:13
January 06 2017 19:11 GMT
#16480
On January 07 2017 02:44 spinesheath wrote:
Always ask yourself if you can split your problem into smaller chunks. Sort first, check after. Simple approach first, optimization after.

Another improvement would be to remove all lines that intersect any other line after each pass. This will make consecutive passes faster in a bad case with many intersecting lines. (in a case with few intersecting lines we will stop early anyways)

On January 07 2017 02:44 spinesheath wrote:
Also Java or rather the JVM is not well equipped for heavy recursion. Don't avoid recursion at all costs, but if you're doing a lot of work with deep recursion, you probably should try to avoid it.

There is some Just-In-Time optimizations which unroll the recursion but those are not quite at the level of the magic functional programming languages do so I agree.
Prev 1 822 823 824 825 826 1032 Next
Please log in or register to reply.
Live Events Refresh
IPSL
17:00
Ro16 Group D
ZZZero vs rasowy
Napoleon vs KameZerg
Liquipedia
PSISTORM Gaming Misc
15:55
FSL teamleague CNvsASH, ASHvRR
Freeedom33
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Railgan 184
IndyStarCraft 110
BRAT_OK 47
MindelVK 29
EmSc Tv 13
StarCraft: Brood War
Britney 25290
Calm 2532
Shuttle 775
Stork 341
firebathero 288
Dewaltoss 113
Barracks 68
Mong 61
Rock 43
Shine 18
Dota 2
Gorgc5830
qojqva1713
Dendi963
Counter-Strike
ScreaM1084
byalli378
Heroes of the Storm
Khaldor535
Liquid`Hasu237
Other Games
Beastyqt573
DeMusliM291
Hui .222
Fuzer 215
Lowko213
Trikslyr46
CadenZie18
Organizations
Dota 2
PGL Dota 2 - Main Stream8971
Other Games
EGCTV625
gamesdonequick359
StarCraft 2
angryscii 24
EmSc Tv 13
EmSc2Tv 13
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• HappyZerGling 71
• HeavenSC 61
• printf 5
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• Kozan
• IndyKCrew
StarCraft: Brood War
• Airneanach42
• HerbMon 6
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2455
• WagamamaTV359
• Ler79
League of Legends
• Nemesis2825
Other Games
• imaqtpie1125
• Shiphtur313
Upcoming Events
OSC
45m
davetesta15
BSL 21
1h 45m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
15h 45m
RSL Revival
15h 45m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
17h 45m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
17h 45m
BSL 21
1d 1h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 1h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 4h
Wardi Open
1d 17h
[ Show More ]
Monday Night Weeklies
1d 22h
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
IPSL
6 days
Julia vs Artosis
JDConan vs DragOn
Liquipedia Results

Completed

Proleague 2025-11-14
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
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
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

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.