• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 05:42
CEST 11:42
KST 18:42
  • 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
Team TLMC #5 - Finalists & Open Tournaments0[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon9[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12
Community News
BSL 2025 Warsaw LAN + Legends Showmatch0Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues29
StarCraft 2
General
#1: Maru - Greatest Players of All Time Weekly Cups (Sept 8-14): herO & MaxPax split cups Team Liquid Map Contest #21 - Presented by Monster Energy SpeCial on The Tasteless Podcast Team TLMC #5 - Finalists & Open Tournaments
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Sparkling Tuna Cup - Weekly Open Tournament SC4ALL $6,000 Open LAN in Philadelphia WardiTV TL Team Map Contest #5 Tournaments RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
Soulkey on ASL S20 ASL TICKET LIVE help! :D BW General Discussion NaDa's Body A cwal.gg Extension - Easily keep track of anyone
Tourneys
[ASL20] Ro16 Group D [ASL20] Ro16 Group C [Megathread] Daily Proleagues BSL 2025 Warsaw LAN + Legends Showmatch
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Borderlands 3 General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
I <=> 9
KrillinFromwales
The Personality of a Spender…
TrAiDoS
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1583 users

The Big Programming Thread - Page 824

Forum Index > General Forum
Post a Reply
Prev 1 822 823 824 825 826 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.
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
Poland17341 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
Poland17341 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 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 18m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Rex 1
StarCraft: Brood War
Calm 5699
Bisu 731
Hyuk 162
HiyA 96
Hyun 96
sorry 86
ToSsGirL 84
Dewaltoss 82
Pusan 77
Light 74
[ Show more ]
Soma 60
actioN 56
Mini 49
ZerO 32
BeSt 30
Liquid`Ret 29
Nal_rA 28
soO 27
Sharp 24
Rush 19
Free 16
SilentControl 10
Dota 2
singsing1260
XcaliburYe206
boxi98170
League of Legends
JimRising 381
Counter-Strike
olofmeister1583
shoxiejesuss598
allub166
Other Games
XaKoH 143
NeuroSwarm80
Trikslyr15
Organizations
StarCraft: Brood War
lovetv 593
Other Games
gamesdonequick587
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos1421
• Stunt679
Other Games
• WagamamaTV81
Upcoming Events
RSL Revival
18m
Maru vs Reynor
Cure vs TriGGeR
Rex1
Map Test Tournament
1h 18m
The PondCast
3h 18m
RSL Revival
1d
Zoun vs Classic
Korean StarCraft League
1d 17h
BSL Open LAN 2025 - War…
1d 22h
RSL Revival
2 days
BSL Open LAN 2025 - War…
2 days
RSL Revival
3 days
Online Event
3 days
[ Show More ]
Wardi Open
4 days
Monday Night Weeklies
4 days
Sparkling Tuna Cup
5 days
LiuLi Cup
6 days
Liquipedia Results

Completed

Proleague 2025-09-10
Chzzk MurlocKing SC1 vs SC2 Cup #2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
RSL Revival: Season 2
Maestros of the Game
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

Upcoming

2025 Chongqing Offline CUP
BSL World Championship of Poland 2025
IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
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.