Thursday, August 4, 2011

In-Place and O(n) Algorithm for finding Palindrome in a SLL

struct list_node *pal; //GLOBAL VAR

void PalindromeCheck(struct list_node *node)
{
static int i=1;
static int mid;

i++;
if ( node->next == NULL )
{
pal=head->start;
if (node->data!=pal->data){
printf("\nNot Palindrome\n");
exit(0);
}
else {
i--;
}
mid=i/2;
return;
}
PalindromeCheck(node->next);
pal=pal->next;
i--;
if ((i >= mid) && (node->data!=pal->data)) {
printf("\nNot Palindrome\n");
exit(0);
}

if (i < mid) {
printf("\nPalindrome\n");
exit(0);
}
}

Tuesday, July 5, 2011

Block Read Performance improvement in __bread()

My Code Changes in __bread function so that we should check the block block number and size limit before looking for the buffer into the Per-CPU cache list and Radix Tree Page Cache in __find_get_block_slow function.

bash-3.2$ diff -u buffer_backup.c fs/buffer.c
--- buffer_backup.c 2011-07-05 13:01:28.950511000 +0530
+++ fs/buffer.c 2011-07-05 13:03:02.339457000 +0530
@@ -1084,18 +1084,6 @@
static struct buffer_head *
__getblk_slow(struct block_device *bdev, sector_t block, int size)
{
- /* Size must be multiple of hard sectorsize */
- if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
- (size < 512 || size > PAGE_SIZE))) {
- printk(KERN_ERR "getblk(): invalid block size %d requested\n",
- size);
- printk(KERN_ERR "logical block size: %d\n",
- bdev_logical_block_size(bdev));
-
- dump_stack();
- return NULL;
- }
-
for (;;) {
struct buffer_head * bh;
int ret;
@@ -1411,7 +1399,21 @@
struct buffer_head *
__bread(struct block_device *bdev, sector_t block, unsigned size)
{
- struct buffer_head *bh = __getblk(bdev, block, size);
+ struct buffer_head *bh;
+
+ /* Size must be multiple of hard sectorsize */
+ if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
+ (size < 512 || size > PAGE_SIZE))) {
+ printk(KERN_ERR "getblk(): invalid block size %d requested\n",
+ size);
+ printk(KERN_ERR "logical block size: %d\n",
+ bdev_logical_block_size(bdev));
+
+ dump_stack();
+ return NULL;
+ }
+
+ bh = __getblk(bdev, block, size);

if (likely(bh) && !buffer_uptodate(bh))
bh = __bread_slow(bh);

Monday, January 17, 2011

Technology to Punish the Guilty

Past weekend I saw the movie "No one killed Jessica", although I knew most of the case history through newspaper feeds and through "Breaking News" no news channels but never got such a real shocker as I got when I saw the movie, after watching the movie I really got the feel of what the family of late Jessica Lal went through while seeking for the justice for her. In spite of aware of the fact that criminal cases usually takes years to come to a conclusion, which is wrong most of the times, I was really sad to see that I took almost 10 years for our judiciary and police to finally nail the culprit.
I think its really a high time in our country to improve the criminal justice system and hence I thought about why not using technology to improve this, no I am not talking about making court records online or online FIR etc., but I am talking about including technology in weapon's itself. What I mean to say that why can't we have a chip in each and every gun/revolver or any such weapon which will have a micro-chip and which needs to be registered with national central server and also linked with the weapon license number, so whenever a person fires the gun the chip will get activated and connected to central server and log some of the data which mentions the lattitude and longitude of site where the gun is fired and the time and other gun details. This I think will then prove to be a very important record for courts to easily prove the person gulty of crime. I know in India people always finds a trick or way to bypass the technological glitches to commit crime but still I think this can be step forward to improve the criminal system in India.